我的代码(不可用):
private static void judgeTextCode(String strFilePath) {
FileInputStream fis = null;
try {
fis = new FileInputStream(strFilePath);
int a = fis.read();
int b = fis.read();
if(a==0xFF&&b==0xFE) {
System.out.println("----------Unicode------");
}
else if(a==0xFE&&b==0xFF) {
System.out.println("----------UTF-16BE------");
}
else if(a==0xEF&&b==0xBB) {
System.out.println("----------UTF-8------");
} else {
System.out.println("----------GBK------");
}
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if(fis != null) {
fis.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
}