<%@ page import="java.io.BufferedInputStream" %>
<%@ page import="java.io.BufferedOutputStream" %>
<%@ page import="java.io.FileInputStream" %>
<%
String fileName = "onedoc.pdf";
String filePath = config.getServletContext().getRealPath("/") + fileName;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
response.setContentType("application/pdf");
try{
bis = new BufferedInputStream(new FileInputStream(filePath));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff,0,buff.length))){
bos.write(buff,0,bytesRead);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(bis != null)
bis.close();
if(bos != null)
bos.close();
}
%>
JSP读取PDF文件页面输出
最新推荐文章于 2023-11-16 10:25:16 发布