package com.my.bus.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class FileUtils {

    /**
     * 合并数据Excel文件
     * @param path 下载地址
     * @param response 请求地址
     * @throws IOException 流
     */
    public static void downFile(String path, HttpServletResponse response) throws IOException {
        InputStream in = new FileInputStream(path); //获取下载文件的输入流
        OutputStream out = null;
        try {
            int count =0;
            byte[] by = new byte[1024];
            //通过response对象获取OutputStream流
            out =  response.getOutputStream();
            while((count=in.read(by))!=-1){
                out.write(by, 0, count);//将缓冲区的数据输出到浏览器
            }
        } catch (Exception e){
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception e){
                e.printStackTrace();
            }
            if(out != null){
                out.flush();
                out.close();

            }
        }

    }

}
