Commit dd6816b1 authored by yanzg's avatar yanzg

文件处理

parent 2b628c26
package com.yanzuoguang.cloud.helper; package com.yanzuoguang.cloud.helper;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
...@@ -54,13 +55,11 @@ public class HttpFileHelper { ...@@ -54,13 +55,11 @@ public class HttpFileHelper {
response.setHeader("Content-disposition", "attachment; filename=" + new String(saveFileName.getBytes("utf-8"), "UTF-8")); response.setHeader("Content-disposition", "attachment; filename=" + new String(saveFileName.getBytes("utf-8"), "UTF-8"));
//设置输出长度 //设置输出长度
response.setHeader("Content-Length", String.valueOf(file.length())); response.setHeader("Content-Length", String.valueOf(file.length()));
ServletOutputStream bos = response.getOutputStream();
// 获取输入流 // 获取输入流
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(serverFilePath)); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(serverFilePath));
try { try {
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
//输出流 //输出流
try {
byte[] buff = new byte[2048]; byte[] buff = new byte[2048];
int readSize = 1; int readSize = 1;
while (readSize > 0) { while (readSize > 0) {
...@@ -69,9 +68,6 @@ public class HttpFileHelper { ...@@ -69,9 +68,6 @@ public class HttpFileHelper {
bos.write(buff, 0, readSize); bos.write(buff, 0, readSize);
} }
} }
} finally {
bos.close();
}
} finally { } finally {
bis.close(); 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