zoukankan      html  css  js  c++  java
  • java判断字符串编码

    public class JudgeCode {
    	
    	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 "";
    	}
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    	}
    
    }


  • 相关阅读:
    单例类
    日期类2
    日历类
    日期转换类
    抓取网页内容并截图
    关于计时器与多线程
    让页面上图片不变形
    Thread 调用方法的方式
    语音放大缩小
    阻止Enter键回发到服务端Asp.net
  • 原文地址:https://www.cnblogs.com/yan456jie/p/5369457.html
Copyright © 2011-2022 走看看