public static String getEncoding(String str) {
String encode = "GB2312";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception) {
}
encode = "ISO-8859-1";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception1) {
}
encode = "UTF-8";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception2) {
}
encode = "GBK";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception3) {
}
encode = "ASCII";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception3) {
}
encode = "Unicode";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception3) {
}
encode = "UTF-16";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception3) {
}
encode = "GB18030";
try {
if (isEncoding(str, encode)) {
return encode;
}
} catch (Exception exception3) {
}
return "";
}
public static boolean isEncoding(String str, String encode) {
try {
if (str.equals(new String(str.getBytes(), encode))) {
return true;
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return false;
}