if (null != agent && -1 != agent.indexOf("MSIE") || null != agent
&& -1 != agent.indexOf("Trident")) {// ie
String name = java.net.URLEncoder.encode(fileNames, "UTF8");
codedfilename = name;
} else if (null != agent && -1 != agent.indexOf("Mozilla")) {// chrome
codedfilename = new String(fileNames.getBytes("utf-8"), "iso-8859-1");
}
我想知道为什么不同浏览器要用不同方式编码, 然后chrome,火狐的编码解码方式的fileNames.getBytes("utf-8")中的utf-8和什么相关,后面的iso-8859-1又和什么相关,我改了数据库编码,文件编码,idea编码,tomcat uri编码,好像都不影响正常编码,我改为new String(fileNames.getBytes("utf-8"), "utf-8")或者new String(fileNames.getBytes("iso-8859-1"), "iso-8859-1")就会乱码.