1 public void test05() throws UnsupportedEncodingException { 2 String strold="abc中文"; 3 byte[] bytesold = strold.getBytes("utf-8"); 4 //数据传到服务器,tomcat使用iso-8859-1进行解码 5 String strtomcat = new String(bytesold,"iso-8859-1"); 6 System.out.println(strtomcat); 7 //还原成原始的字符串 8 //将解错的编码使用iso-8859-1变回原来的字节数组,在使用utf-8解码 9 // byte[] bytes2 = strtomcat.getBytes("iso-8859-1"); 10 // String rightStr=new String(bytes2,"utf-8"); 11 // System.out.println(rightStr); 12 System.out.println(new String(strtomcat.getBytes("iso-8859-1"),"utf-8")); 13 14 } 15 }