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();
    }
相关推荐
.唉几秒前
06. FastAPI框架从入门到实战
python·fastapi·web
随风,奔跑13 小时前
Nginx
服务器·后端·nginx·web
曲幽21 小时前
初探:用 FastAPI 搭建你的第一个 AI Agent 接口
python·ai·llm·agent·fastapi·web·chat·httpx·ollama
码界奇点3 天前
基于Python的微信公众号爬虫系统设计与实现
开发语言·爬虫·python·毕业设计·web·源代码管理
Panzer_Jack3 天前
Copiwaifu:一个和 Claude Code、Codex、Copilot 等 AI 编程工具联动的 Live2D 桌宠[特殊字符]
前端·人工智能·copilot·web·live2d·pixi.js·easy-live2d
Y001112363 天前
JavaWeb-end
java·servlet·web
里欧跑得慢4 天前
CSS 嵌套:编写更优雅的样式代码
前端·css·flutter·web
里欧跑得慢4 天前
CSS变量与自定义属性详解
前端·css·flutter·web
abcnull4 天前
Springboot+Vue2的Web项目小白入门Demo快速学习!
java·elementui·vue·maven·springboot·web·小白
里欧跑得慢5 天前
Flutter 主题管理:构建一致的用户界面
前端·css·flutter·web