java_获取字符串编码(待完善)
程序员文章站
2022-07-14 19:40:39
...
该获取方式不合理,后续改进;
/**
* 获取字符串编码;
* @param str 字符串参数;
* @return 返回字符串编码格式;
*/
public static String [] getEncoding(String str) {
int i = 0;
String [] encodeing = new String[3];
String [] encode = {"GB2312","ISO-8859-1","UTF-8","GBK"};
for(String this_encode : encode){
try {
byte[] bytes = str.getBytes(this_encode);
String string = new String(bytes,this_encode);
if(str.equals(string)){
encodeing[i++] = this_encode;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return encodeing;
}
上一篇: 判断字符串编码类型