编码解码相关

新手上路,请多包涵
   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")就会乱码.

阅读 1.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题