文件下载
程序员文章站
2022-06-20 09:00:08
...
protected void readFile(InputStream in, String fileName,
HttpServletResponse response) {
ServletOutputStream out = null;
try {
response
.setContentType("application/octet-stream;charset=ISO8859-1");
response.setHeader("Content-Disposition", "attachment;filename="
+ fileName);
out = response.getOutputStream();
byte[] b = new byte[100];
while (in.read(b) != -1) {
out.write(b);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
下一篇: 蛋糕怎么做,学会了保证一次成功