web响应不同类型的文件

java 复制代码
    @GetMapping("/show")
    public void show(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String filename = request.getParameter("filename");
        String mimeType = request.getServletContext().getMimeType(filename);
        File file = new File("E:/" + filename);
        response.setContentType(mimeType);
        FileInputStream fileInputStream = new FileInputStream(file);
        ServletOutputStream outputStream = response.getOutputStream();
        int len = 0;
        byte[] bytes = new byte[8 * 1024];
        while ((len = fileInputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, len);
        }
        fileInputStream.close();
        outputStream.close();
    }
相关推荐
湮w2 天前
JavaWeb(三)JavaScript详细讲解
java·javascript·web
还是鼠鼠3 天前
AI掘金头条新闻系统 (Toutiao News)-缓存相关推荐新闻
后端·python·mysql·fastapi·web
曲幽3 天前
从卡顿到丝滑:FastAPI 调用外部 API 的正确姿势(httpx 实战)
python·fastapi·web·async·httpx·client·await·requests·aiohttp
还是鼠鼠6 天前
AI掘金头条新闻系统 (Toutiao News)-缓存新闻详情
后端·python·mysql·fastapi·web
曲幽12 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
带刺的坐椅14 天前
Spring Boot → Solon 注解迁移实战指南:一张对照表说清楚
java·springboot·web·solon
曲幽18 天前
刚部署的 LibreTranslate 频频翻车?我掏出了 20 年前的 StarDict 词典,用 FastAPI 搭了个本地词典翻译 API
python·fastapi·web·translate·goldendict·libretranslate·stardict·pystardict
曲幽19 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
llz_11225 天前
web-第四次课后作业
前端·spring boot·web
天山@1231 个月前
电商系统Web渗透测试实战学习笔记
web·电商系统