pb solved with this:
File file = new File("D:forDownloadpdfs\"+bean.getCode()+".pdf");
InputStream fis = new FileInputStream(file);
byte[] buf = new byte[204800];
int offset = 0;
int numRead = 0;
while ((offset < buf.length) && ((numRead = fis.read(buf, offset, buf.length - offset)) >= 0))
{
offset += numRead;
}
fis.close();
HttpServletResponse response =
(HttpServletResponse) FacesContext.getCurrentInstance()
.getExternalContext().getResponse();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename="+bean.getCode()+".pdf");
response.getOutputStream().write(buf);
response.getOutputStream().flush();
response.getOutputStream().close();
FacesContext.getCurrentInstance().responseComplete();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…