public static void browsePDF(HttpServletResponse response, String PDF) throws IOException {
response.setContentType("application/pdf");
FileInputStream in = new FileInputStream(new File(PDF));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b)) != -1) {
out.write(b);
}
out.flush();
in.close();
out.close();
}
public static void browsePNG(HttpServletResponse response, String PNG){
InputStream is = null;
OutputStream os = null;
try {
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/png");
File filePNG = new File(PNG);
response.addHeader("Content-Length", "" + filePNG.length());
is = new FileInputStream(filePNG);
os = response.getOutputStream();
IOUtils.copy(is, os);
} catch (Exception e) {
logger.info("异常-->{}",e);
} finally {
try {
if (os != null) {
os.flush();
os.close();
}
if (is != null) {
is.close();
}
} catch (IOException e) {
}
}
}
java在线浏览PDF+PNG(上线项目)
最新推荐文章于 2023-03-07 10:47:16 发布