• 下载文件


    package com.tszr.mango.common.utils;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    
    import javax.servlet.http.HttpServletResponse;
    
    public class FileUtils {
    
        /**
         * 下载文件
         * 
         * @param response
         * @param file
         * @param newFileName
         */
        public static void downloadFile(HttpServletResponse response, File file, String newFileName) {
            try {
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + new String(newFileName.getBytes("ISO-8859-1"), "UTF-8"));
                BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
                InputStream is = new FileInputStream(file.getAbsolutePath());
                BufferedInputStream bis = new BufferedInputStream(is);
                int length = 0;
                byte[] temp = new byte[1 * 1024 * 10];
                while ((length = bis.read(temp)) != -1) {
                    bos.write(temp, 0, length);
                }
                bos.flush();
                bis.close();
                bos.close();
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    蓝桥杯国赛--四阶幻方清晰易懂(dfs+剪枝,stl)
    蓝桥杯---九宫重排(典型bfs)
    快速排序算法细致总结!!!
    Topsis优劣解距离分析法
    golang变量的定义
    golang
    erlang的优缺点
    mongrel代码注解
    取石块 解题报告
    军队 解题报告
  • 原文地址:https://www.cnblogs.com/tszr/p/15941867.html
Copyright © 2020-2023  润新知