atitit.Atitit.检测文本文件的编码 java  与php版  。Net

atitit.Atitit.检测文本文件的编码 java  php版  。Net

 

 

检测编码原理

Utf8》》gbk

在此转会gbk》》utf

 

 

 

 

工具检测编码

不能使用load来检测编码..

 

 

要是txt是 gbk使用notepad++ load as utf8 三正常的...

Load as gbk 却乱码了...

 

 

Editplusok...

 

 

不过.要是文件是utf8.. Editplus  load as gbk 显示是正常的..所以,不能使用load来检测编码..

 

作者:: 绰号:老哇的爪子 ( 全名::Attilax akbar al rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://www.cnblogs.com/attilax/

 

使用convert来检测编码

使用convert来检测编码..docu>>file encode >>convet encode  显示编码确认框..这个走十恰当的的编码...

 

也可以使用notepad的另存为来检测..

 

编程api方式检测编码

public class EncodeCheckor {

 

public static void main(String[] args) {

// TODO Auto-generated method stub

String f = pathx.classPath() + "/aaaNaming/names.txt";

System.out.println(getEncode(f));

}

 

private static String getEncode(String f) {

// TODO Auto-generated method stub

String t = filex.read(f);

String $zh = t;

;

String $s1 = iconv("UTF-8""gb2312"$zh);

String $s2 = iconv("gb2312""UTF-8"$s1);

if ($s2 .equals( $zh)) {

return "utf-8";

// if utf code , convert2 gbk mode

return "gbk";

}

 

private static String iconv(String encode1, String encode2, String str) {

byte[] temp = null;

try {

temp = str.getBytes(encode1);

catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}// 这里写原编码方式

String newStr = null;

try {

newStr = new String(tempencode2);

catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}// 这里写转换后的编码方式

 

return newStr;

}

 

}

 

 

 

 

原文地址:https://www.cnblogs.com/attilax/p/5123051.html