whycxzp
2022-12-07 00e4715a062585ad8e4f9dbaea8910b06e8ff228
src/main/java/com/whyc/util/FileUtil.java
@@ -1,6 +1,8 @@
package com.whyc.util;
import java.io.File;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@@ -60,6 +62,28 @@
        return true;
    }
    public static void download(HttpServletResponse resp,String inFilePath,String outFileFullName){
        try {
            // 转码防止乱码
            //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1"));
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( outFileFullName, "utf-8"));
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(inFilePath);
            int len=0;
            byte[] buffer =new byte[1024];
            //7. 将缓冲区中的数据输出
            while ((len=in.read(buffer))>0){
                out.write(buffer,0,len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        File file = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207泰州平台");
        List list = new ArrayList<>();