java检测乱码原编码

来源:互联网 发布:淘宝衣服评价语 编辑:程序博客网 时间:2024/04/30 10:53

public static String getEncoding(String str) {             String encode = "GB2312";            try {                if (str.equals(new String(str.getBytes(encode), encode))) {                     String s = encode;                     System.out.println(new String(str.getBytes(encode), "utf-8"));                return s;                 }             } catch (Exception exception) {             }             encode = "ISO-8859-1";            try {                if (str.equals(new String(str.getBytes(encode), encode))) {                     String s1 = encode;                     System.out.println(new String(str.getBytes(encode), "utf-8"));                return s1;                 }             } catch (Exception exception1) {             }             encode = "UTF-8";            try {                if (str.equals(new String(str.getBytes(encode), encode))) {                     String s2 = encode;                     System.out.println(new String(str.getBytes(encode), "utf-8"));                return s2;                 }             } catch (Exception exception2) {             }             encode = "GBK";            try {                if (str.equals(new String(str.getBytes(encode), encode))) {                     String s3 = encode;                    System.out.println(new String(str.getBytes(encode), "utf-8"));                return s3;                 }             } catch (Exception exception3) {             }            return "";         }

0 0
原创粉丝点击