java 判断字符串什么编码类型
生活随笔
收集整理的這篇文章主要介紹了
java 判断字符串什么编码类型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public static String getEncoding(String str) {
String encode = "GB2312";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s = encode;
return s;
}
} catch (Exception exception) {
}
encode = "ISO-8859-1";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s1 = encode;
return s1;
}
} catch (Exception exception1) {
}
encode = "UTF-8";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s2 = encode;
return s2;
}
} catch (Exception exception2) {
}
encode = "GBK";
try {
if (str.equals(new String(str.getBytes(encode), encode))) {
String s3 = encode;
return s3;
}
} catch (Exception exception3) {
}
return "";
}
String encode = "ISO-8859-1"; //應用延伸
try {
if (customer.equals(new String(customer.getBytes(encode), encode))) {
customer = new String(customer.getBytes(encode),"utf-8");
}
} catch (Exception exception1) {
}
總結
以上是生活随笔為你收集整理的java 判断字符串什么编码类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Direct2D教程(三)简单几何图形
- 下一篇: ARM FVP(固定虚拟平台)Linux