日期:2014-05-18 浏览次数:20645 次
realPath = new String(realPath.getBytes("ISO-8859-1"), "GB2312");
filename = URLEncoder.encode(filename, "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename="
+ new String(filename.getBytes("ISO-8859-1"), "UTF-8"));
SAXReader reader = new SAXReader();
Document document = null;
try {
document = reader.read(new File(realPath));
} catch (DocumentException e) {
e.printStackTrace();
}
response.getWriter().write(document.asXML().toString());
System.out.println(document.asXML().toString());
response.setContentType("application/x-msdownload");
response.addHeader("Content-Disposition", "attachment;filename="
+ new String(filename.getBytes("ISO-8859-1"), "UTF-8"));
InputStream inputStream = new FileInputStream(new?File(realPath));
OutputStream outputStream = response.getOutputStream();
byte[] buffer = new byte[1024];
int i;
while ((i = inputStream.read(buffer)) != -1) {
len += i;
outputStream.write(buffer, 0, i);
outputStream.flush();
}
response.setContentLength(len);
outputStream.close();
inputStream.close();