新增了 流下载方法
This commit is contained in:
parent
5852034f7e
commit
fb848e7400
@ -88,4 +88,25 @@ public class RequestUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
*
|
||||||
|
* @param response
|
||||||
|
* @param inputStream
|
||||||
|
* @param outFileName
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static void download(HttpServletResponse response, InputStream inputStream, String outFileName) throws IOException {
|
||||||
|
try (OutputStream outputStream = response.getOutputStream()) {
|
||||||
|
response.setHeader("content-type", "application/octet-stream");
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(outFileName, "UTF-8"));
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
for (int readLength; (readLength = inputStream.read(buf)) > 0; ) {
|
||||||
|
outputStream.write(buf, 0, readLength);
|
||||||
|
}
|
||||||
|
outputStream.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user