java 判断字符串编码

String iso8859 = new String(sb.toString().getBytes("iso8859-1"));
String gbk = new String(sb.toString().getBytes("gbk"));
String utf8 = new String(sb.toString().getBytes("utf-8"));
if(iso8859.equals(sb.toString())){
System.out.println("iso8859");
}else if(gbk.equals(sb.toString())){
System.out.println("gbk");
}else if(utf8.equals(sb.toString())){
System.out.println("utf8");
}

你可能感兴趣的:(java 判断字符串编码)