package com.reapal.cache; import java.nio.charset.Charset; import java.util.Iterator; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by jack on 2015/9/24. */ public class test { public static void main(String[] args) throws Exception { String aaa = "你的乱码"; aaa = new String(aaa.getBytes(),"UTF-8"); Set<String> charSetCodes = Charset.availableCharsets().keySet(); for(String a : charSetCodes){ for(String b : charSetCodes){ if(!a.equals(b)){ String desStr = new String(aaa.getBytes(a),b); if(isContainChinese(desStr)) { System.out.println(" a=" + a + " b=" + b + " 结果为:" + desStr); } } } } } //判断是否包含中文 public static boolean isContainChinese(String str) { Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); Matcher m = p.matcher(str); if (m.find()) { return true; } return false; } }
中问乱码的解决之道
最新推荐文章于 2024-07-12 00:00:00 发布
19万+

被折叠的 条评论
为什么被折叠?



