java乱码解决方案

  • Post author:
  • Post category:java


可以通过以下方法找到之前的编码格式

public class Test {

    public static void main(String agr[]) throws UnsupportedEncodingException {
        recover("package jit.wxs.express;");
    }
    
    
    public static void recover(String str) 
            throws UnsupportedEncodingException{
        String[] charsets = new String[]{"windows-1252","GB18030","Big5","UTF-8","GBK","ISO-8859-1",
                "ASCII","GB2312","UTF-16"};
        for(int i=0;i<charsets.length;i++){
            for(int j=0;j<charsets.length;j++){
                if(i!=j){
                    String s = new String(str.getBytes(charsets[i]),charsets[j]);
                    System.out.println("---- 原来编码(A)假设是: "+charsets[j]+", 被错误解读为了(B): "+charsets[i]);
                    System.out.println(s);
                    System.out.println();    
                }
            }
        }
    } 
}

他们之间相互匹配,然后找到之前的编码格式



版权声明:本文为qq_32419139原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。