字符串编码类型判断
package com.kay.base.util;
/**
* Author: wangliang
* Date: 2016/10/9
* Time: 16:05
* E-mail: wl_bhne@163.com
*/
public class Encoding {
public static String getEncoding(String str) {
String encode = "GB2312";
try {
if(str.equals(new String(str.getBytes(),encode))){
String result = encode;
return result;
}
}catch (Exception exception){
}
String encode1 = "ISO-8859-1";
try {
if(str.equals(new String(str.getBytes(),encode1))){
String result1 = encode1;
return result1;
}
}catch (Exception exception){
}
String encode2 = "UTF-8";
try {
if(str.equals(new String(str.getBytes(),encode2))){
String result2 = encode2;
return result2;
}
}catch (Exception exception){
}
String encode3 = "GBK";
try {
if(str.equals(new String(str.getBytes(),encode3))){
String result3 = encode3;
return result3;
}
}catch (Exception exception){
}
return "";
}
}