火狐下载文件中文名是乱码,谷歌没问题,大家遇到过没,求教
4 回复
OutputStream out = null;
InputStream in = null;
try {
// 获得文件名
String filename = URLEncoder.encode(file.getName(), "UTF-8");
// 定义输出类型(下载)
response.setContentType("application/force-download");
response.setHeader("Location", filename);
// 定义输出文件头
response.setHeader("Content-Disposition", "attachment;filename="
+ filename);
out = response.getOutputStream();
in = new FileInputStream(file.getPath());
byte[] buffer = new byte[1024];
int i = -1;
while ((i = in.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
}catch(Exception e) {
if(in != null){
in.close();
if(out!=null)
out.close();
}
}finally {
if(in != null){
in.close();
if(out!=null)
out.close();
}
}
添加回复
请先登陆