java导出文件文件名中文乱码

try {
oldFileName = new String(oldFileName.getBytes("ISO8859-1"), "UTF-8");//转换文件名,防止乱码
String userAgent = request.getHeader("User-Agent");
byte[] bytes = userAgent.contains("MSIE")||(userAgent.indexOf("Gecko")>0 && userAgent.indexOf("rv:11")>0) ? oldFileName.getBytes() : oldFileName.getBytes("UTF-8"); // fileName.getBytes("UTF-8")处理safari的乱码问题
oldFileName = new String(bytes, "ISO-8859-1");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName="+oldFileName);

你可能感兴趣的:(java)