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) {      
             }  

 

posted @ 2014-12-11 17:56  君子笑而不语  阅读(1207)  评论(0编辑  收藏  举报