您的位置:首页 > 编程语言 > Java开发

Java文件下载乱码问题

2016-06-24 16:55 417 查看
最近项目中有需要批量下载的功能,在实现功能的过程中碰到了乱码问题及Mac上下载后带exe后缀,记录下解决方法。

1、关于文件乱码问题:

public static String decode(String userAgent, String fileName) throws Exception {
if (userAgent.indexOf("MSIE") >= 0) {
return URLEncoder.encode(fileName, "UTF8");// IE
} else if (userAgent.indexOf("Mozilla") >= 0) {
return new String(fileName.getBytes("UTF-8"), "ISO-8859-1");// chrome,火狐,Safari
} else {
return URLEncoder.encode(fileName, "UTF8");// 其他浏览器
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Java 乱码