/** * 判断文件的编码格式
* @param fileName :file
* @return 文件编码格式
* @throws Exception */
public static String codeString(String fileName) throws Exception{
BufferedInputStream bin = new BufferedInputStream(
new FileInputStream(fileName));
int p = (bin.read() << 8) + bin.read();
String code = null;
switch (p) {
case 0xefbb:
code = "UTF-8";
break;
case 0xfffe:
code = "Unicode";
break;
case 0xfeff:
code = "UTF-16BE";
break;
default:
code = "GBK";
}
return code; }
}请问这个方法能不能对一个文件进行判读并返回改文本文件的编码方式!!
0xfffe 这个是判断的是什么,求详细讲解。。。。基础不牢了 |