Java 文件下载
Code
out = new BufferedOutputStream(response.getOutputStream());
if (valueMap == null) {
isSuc = true;
return;
}
if (ret.endsWith("output.xls")) {
// 文件下载
response.setContentType("application/octet-stream; CHARSET=GB2312");
response.setHeader("Content-Disposition", "attachment; filename="
+ response.encodeURL(new String("数据更新结果.xls".getBytes("gb2312"), "iso8859-1")));
System.out.println("ret file name" + ret);
SmartUpload su = new SmartUpload();
su.initialize(servletConfig, request, response);
su.setContentDisposition(null);
su.downloadFile(ret);
File file = new File(ret);
byte[] buff = new byte[512];
in = new BufferedInputStream(new FileInputStream(file));
while ((in.read(buff) != -1)) {
out.write(buff);
}
if (file.exists())//删除文件
file.delete();
} else {
isSuc = true;
}
out = new BufferedOutputStream(response.getOutputStream());
if (valueMap == null) {
isSuc = true;
return;
}
if (ret.endsWith("output.xls")) {
// 文件下载
response.setContentType("application/octet-stream; CHARSET=GB2312");
response.setHeader("Content-Disposition", "attachment; filename="
+ response.encodeURL(new String("数据更新结果.xls".getBytes("gb2312"), "iso8859-1")));
System.out.println("ret file name" + ret);
SmartUpload su = new SmartUpload();
su.initialize(servletConfig, request, response);
su.setContentDisposition(null);
su.downloadFile(ret);
File file = new File(ret);
byte[] buff = new byte[512];
in = new BufferedInputStream(new FileInputStream(file));
while ((in.read(buff) != -1)) {
out.write(buff);
}
if (file.exists())//删除文件
file.delete();
} else {
isSuc = true;
}