1. String fileName=new String(URLEncoder.encode(fileName,"utf-8")); getResponse().addHeader("Content-Disposition","attachment;filename="+fileName); 或者 ...
1. String fileName=new String(URLEncoder.encode(fileName,"utf-8"));
getResponse().addHeader("Content-Disposition","attachment;filename="+fileName);
或者new String(fileName.getBytes(),"utf-8")
//都是亂碼%E8%B5%84%E5%AE%A1%E6%96%87%E4%BB%B6%E6%A8%A1%E6%9D%BF
2.使用gbk呢,不管是URLEncoder.encode還是fileName.getBytes()都也是亂碼 //如 ____.txt
3. 使用ISO8859-1呢
String fileName=new String(URLEncoder.encode(fileName,"ISO8859-1"));
//亂碼 %3F%3F%3F%3F%3F%3F.txt
只有在
new String(fileName.getBytes(),"ISO8859-1"); //正確,不發生亂碼
總之一句話,Java下載文件時文件名用new String(fileName.getBytes(),"ISO8859-1"); 轉碼就對了。