Commit dd6816b1 authored by yanzg's avatar yanzg

文件处理

parent 2b628c26
package com.yanzuoguang.cloud.helper;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URL;
......@@ -54,13 +55,11 @@ public class HttpFileHelper {
response.setHeader("Content-disposition", "attachment; filename=" + new String(saveFileName.getBytes("utf-8"), "UTF-8"));
//设置输出长度
response.setHeader("Content-Length", String.valueOf(file.length()));
ServletOutputStream bos = response.getOutputStream();
// 获取输入流
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(serverFilePath));
try {
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
//输出流
try {
byte[] buff = new byte[2048];
int readSize = 1;
while (readSize > 0) {
......@@ -69,9 +68,6 @@ public class HttpFileHelper {
bos.write(buff, 0, readSize);
}
}
} finally {
bos.close();
}
} finally {
bis.close();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment