使用springboot如何实现下载单或多的zip文件-创新互联
今天就跟大家聊聊有关使用springboot如何实现下载单或多的zip文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

单文件下载
//下载单个文件
public void downloadFile(HttpServletResponse response){
String path = "D:\test\ce\1.txt"
File file = new File(path);
if(file.exists()){
String fileName = file.getName();
response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
download(response,file);
}
}
public void download(HttpServletResponse response,File file){
FileInputStream fis = null;
BufferedInputStream bis = null;
OutputStream os = null;
try {
os = response.getOutputStream();
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
byte[] buffer = new byte[bis.available()];
int i = bis.read(buffer);
while(i != -1){
os.write(buffer, 0, i);
i = bis.read(buffer);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
bis.close();
fis.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
} 网站名称:使用springboot如何实现下载单或多的zip文件-创新互联
当前地址:http://www.jxjierui.cn/article/djcgdh.html


咨询
建站咨询
