23,402
社区成员




out.clear();
response.setContentType("application/pdf");
try {
String strPdfPath = new String("D://Hibernate In Action 1.pdf");
//判断该路径下的文件是否存在
File file = new File(strPdfPath);
if (file.exists()) {
BufferedOutputStream temps = new BufferedOutputStream(response
.getOutputStream());
BufferedInputStream in = new BufferedInputStream(
new FileInputStream(strPdfPath));
byte[] buf = new byte[2048];
while ((in.read(buf)) != -1) {
temps.write(b);
temps.flush();
}
in.close();
temps.close();
} else {
out.print(strPdfPath + " 文件不存在!");
}
} catch (Exception e) {
out.println(e.getMessage());
}