一、工具类
private void downloadFile(HttpServletResponse httpServletResponse, String fileName, String filePath) {
File file = new File(filePath);
InputStream inputStream = null;
OutputStream outputStream = null;
byte[] bytes = new byte[1024];
try {
inputStream = new FileInputStream(file);
httpServletResponse.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
outputStream = httpServletResponse.getOutputStream();
int i;
while ((i = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, i);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
assert outputStream != null;
outputStream.close();
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}