// 设置为下载application/x-download
resp.setContentType("application/x-download");
// 下载后的文件名称
String downloadFileName = "abc.txt";
// 编码转换
downloadFileName = URLEncoder.encode(downloadFileName, "UTF-8");
resp.addHeader("Content-Disposition", "attachment;filename="
+ downloadFileName);
try {
OutputStream os = resp.getOutputStream();
FileInputStream fis = new FileInputStream(filePath);
byte[] b = new byte[1024]
int i = 0;
while ((i = fis.read(b)) > 0) {
os.write(b, 0, i);
}
fis.close();
os.flush();
os.close();
}
下载
最新推荐文章于 2022-11-21 00:10:59 发布