/**
* 编码变为utf-8
*/
public static String encode2utf8(String str) {    
        String encode = "GB2312";    
       try {    
           if (str.equals(new String(str.getBytes(encode), encode))) {    
                String s = encode;
                System.out.println(encode);
               return new String(str.getBytes(encode), "utf-8");    
            }    
        } catch (Exception exception) {    
        }    
        encode = "ISO-8859-1";    
       try {    
           if (str.equals(new String(str.getBytes(encode), encode))) {    
                String s1 = encode;   
                System.out.println(encode);
               return new String(str.getBytes(encode), "utf-8");   
            }    
        } catch (Exception exception1) {    
        }    
        encode = "UTF-8";    
       try {    
           if (str.equals(new String(str.getBytes(encode), encode))) {    
                String s2 = encode; 
                System.out.println(encode);
               return new String(str.getBytes(encode), "utf-8");    
            }    
        } catch (Exception exception2) {    
        }    
        encode = "GBK";    
       try {    
           if (str.equals(new String(str.getBytes(encode), encode))) {    
                String s3 = encode; 
                System.out.println(encode);
               return new String(str.getBytes(encode), "utf-8");    
            }    
        } catch (Exception exception3) {    
        }    
       return "";    
    }更多内容请访问:IT源点
注意:本文归作者所有,未经作者允许,不得转载
 
 
            