在我的列表中,我有多个文件,但在下载时仅下载列表中的第一个文件。
for(FileAttachemntActionVo fileAttachemntActionVoItr : fileAttachemntActionVoList){
ServletOutputStream out = servletResponse.getOutputStream();
servletResponse.setContentType("multipart/x-mixed-replace;boundary=END");
servletResponse.setHeader("Content-Disposition","attachment; filename="+fileAttachemntActionVoItr.getAttachmentFileName());
//}
FileInputStream fileInputStream = null;
try{
fileInputStream = new FileInputStream(fileAttachemntActionVoItr.getAttachmentUrl() + fileAttachemntActionVoItr.getAttachmentFileName());
}catch(FileNotFoundException fnfe){
fnfe.getStackTrace();
}
BufferedInputStream fif = new BufferedInputStream(fileInputStream);
int i = 0;
while ((i = fif.read()) != -1) {
out.write(i);
}
fif.close();
out.close();
}
最佳答案
不要关闭输出流,看看this post 。让容器处理流。
关于java - java中下载多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44697863/