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,23 +55,18 @@ 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) {
readSize = bis.read(buff, 0, buff.length);
if (readSize > 0) {
bos.write(buff, 0, readSize);
}
byte[] buff = new byte[2048];
int readSize = 1;
while (readSize > 0) {
readSize = bis.read(buff, 0, buff.length);
if (readSize > 0) {
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