<%@page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="java.util.*"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.URLEncoder" %>
<%
try {
String filename = "123.pdf";
File file = new File("D:\\demo\\WEAVERZTL\\ecology\\123.pdf");
FileInputStream is = new FileInputStream(file);
response.setContentType("application/pdf");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
OutputStream os = response.getOutputStream();
if (is != null) {
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
}
is.close();
os.close();
System.out.println("下载le..。");
} catch (IOException e) {
e.printStackTrace();
System.out.println("下载异常了。。。。。");
}
%>
以上时下载问文件的代码,下载后文件比原文件大几十kb,且打不开,这是咋回事啊?