//提供如下工具类将 文件名编码 就可以啦
public static String toUtf8String(HttpServletRequest request, String s) {
String agent = request.getHeader("User-Agent");
try {
boolean isFireFox = (agent != null && agent.toLowerCase().indexOf("firefox") != -1);
if (isFireFox) {
s = new String(s.getBytes("UTF-8"), "ISO8859-1");
} else {
s = toUtf8String(s);
if ((agent != null && agent.indexOf("MSIE") != -1)) {
// see http://support.microsoft.com/default.aspx?kbid=816868
if (s.length() > 150) {
// 根据request的locale 得出可能的编码
s = new String(s.getBytes("UTF-8"), "ISO8859-1");
}
}
}
} catch (UnsupportedEncodingException e) {
log.error("将文件名中的汉字转为UTF8编码的串时错误,输入的字符串为:" + s);
}
return s;
}
不兼容浏览器: firebox