码迷,mamicode.com
首页 > 编程语言 > 详细

java 判断字符串什么编码类型

时间:2014-12-11 18:57:15      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   sp   java   on   div   log   

     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 判断字符串什么编码类型

标签:style   blog   io   color   sp   java   on   div   log   

原文地址:http://www.cnblogs.com/aixin0428/p/4158185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!