/**
* 获取不同TXT文件的编码格式
*
* @param fileName 文件全路径
* @return
* @throws IOException
*/
public static String getCharset(String fileName) throws IOException{
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";
}
bin.close();
System.out.println("编码:" + code);
return code;
}