- 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;
- }
关于文件读取时编码问题
原文:http://www.cnblogs.com/geqbleo/p/5692318.html