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();
    }
相关推荐
quxuexi5 小时前
网络通信安全与可靠传输:从加密到认证,从状态码到可靠传输
java·安全·web
曲幽9 小时前
FastAPI+Vue:文件分片上传+秒传+断点续传,这坑我帮你踩平了!
python·vue·upload·fastapi·web·blob·chunk·spark-md5
身如柳絮随风扬2 天前
Servlet:访问流程、核心接口与生命周期
java·servlet·web
钛态2 天前
前端WebSocket实时通信:别再用轮询了!
前端·vue·react·web
爱学习的程序媛2 天前
浏览器内核揭秘:JavaScript 和 UI 的“主线程争夺战”
前端·性能优化·浏览器·web
曲幽3 天前
FastAPI自动生成的API文档太丑?我花了一晚上把它改成了客户愿意付费的样子
python·fastapi·web·swagger·openapi·scalar·docs
曲幽5 天前
告别手写 API 胶水代码:FastAPI 与 Vue 的“契约自动机” OpenAPI 实战
python·typescript·vue·fastapi·web·swagger·openapi·codegen
里欧跑得慢5 天前
Flutter 导航路由:构建流畅的应用导航体验
前端·css·flutter·web
数据知道6 天前
claw-code 源码详细分析:Command Graph 分段——复杂 CLI 产品如何把命令关系从脑子里搬到纸上?
ai·web·claw code
曲幽7 天前
FastAPI + Vue 前后端分离实战:我的项目结构“避坑指南”
python·vue·fastapi·web·vite·proxy·cors·env