Java字符编码转换
// GBK转UTF-8 public String gbkToUtf8(String str) throws UnsupportedEncodingException { String iso=new String(str.getBytes("UTF-8"), "ISO-8859-1"); for(byte b:iso.getBytes("ISO-8859-1")){} return new String(iso.getBytes("ISO-8859-1"),"UTF-8"); }
// UTF-8转GBK public String utf8ToGbk(String str) throws UnsupportedEncodingException { String iso=new String(str.getBytes("GB2312"), "ISO-8859-1"); for(byte b:iso.getBytes("ISO-8859-1")){} return new String(iso.getBytes("ISO-8859-1"),"GB2312"); }