码迷,mamicode.com
首页 > 其他好文 > 详细

查看参数编码

时间:2017-03-08 11:21:53      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:内容   返回   ati   pre   return   gb2312   ret   span   代码   

public static String getEncoding(String str) {      
           String encode = "GB2312";      
          try {      
              if (str.equals(new String(str.getBytes(encode), encode))) {      //判断是不是GB2312
                   String s = encode;      
                  return s;      //是的话,返回“GB2312“,以下代码同理
               }      
           } catch (Exception exception) {      
           }      
           encode = "ISO-8859-1";      
          try {      
              if (str.equals(new String(str.getBytes(encode), encode))) {      //判断是不是ISO-8859-1
                   String s1 = encode;      
                  return s1;      
               }      
           } catch (Exception exception1) {      
           }      
           encode = "UTF-8";      
          try {      
              if (str.equals(new String(str.getBytes(encode), encode))) {   //判断是不是UTF-8
                   String s2 = encode;      
                  return s2;      
               }      
           } catch (Exception exception2) {      
           }      
           encode = "GBK";      
          try {      
              if (str.equals(new String(str.getBytes(encode), encode))) {      //判断是不是GBK
                   String s3 = encode;      
                  return s3;      
               }      
           } catch (Exception exception3) {      
           }      
          return "";        //如果都不是,说明输入的内容不属于常见的编码格式。
       }

 

查看参数编码

标签:内容   返回   ati   pre   return   gb2312   ret   span   代码   

原文地址:http://www.cnblogs.com/duoqingxiaohao/p/6518000.html

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