首页 > 其他 > 详细

查看参数编码

时间:2017-03-08 11:21:53      阅读:156      评论:0      收藏:0      [点我收藏+]
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 "";        //如果都不是,说明输入的内容不属于常见的编码格式。
       }

 

查看参数编码

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!