zoukankan      html  css  js  c++  java
  • java 获取获取字符串编码格式

    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 ""; //如果都不是,说明输入的内容不属于常见的编码格式。
    ---------------------
    作者:微wx笑
    来源:CSDN
    原文:https://blog.csdn.net/testcs_dn/article/details/53982619
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    USACO 2016 February Contest, Gold解题报告
    USACO 2016 January Contest, Gold解题报告
    NOIP2013 Day2
    [DP题]放苹果
    [DP题]登山
    洛谷八连测R6
    [20171025模拟赛]
    [DP题]吃糖果
    [DP题]采药
    spring-security-oauth2 授权服务集成钉钉扫码登录
  • 原文地址:https://www.cnblogs.com/shizhijie/p/10096201.html
Copyright © 2011-2022 走看看