response.setContentType("application/pdf");
FileInputStream in;
OutputStream out;
//路径
String path = "I:\\622.pdf";
try {
in = new FileInputStream(new File(path));
out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b)) != -1) {
out.write(b);
}
out.flush();
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
以流的方式读取PDF返回给前端
最新推荐文章于 2023-10-24 19:10:33 发布
本文介绍了一种在Java Web应用中实现PDF文件下载的方法,通过设置响应类型为application/pdf,并使用FileInputStream读取PDF文件,然后通过OutputStream将文件写入HTTP响应,从而实现在浏览器中直接下载PDF文件。
1152

被折叠的 条评论
为什么被折叠?



