public static String getFileCharacterEnding(File file) throws Exception {
InputStream inputStream = new FileInputStream(file);
byte[] head = new byte[3];
inputStream.read(head);
String code = "gbk";
if (head[0] == -1 && head[1] == -2){
code = "UTF-16";
}
if (head[0] == -2 && head[1] == -1){
code = "Unicode";
}
if (head[0] == -17 && head[1] == -69 && head[2] == -65){
code = "UTF-8";
}
System.out.println(code);
return code;
}
JAVA 判断TXT文件编码格式
最新推荐文章于 2021-03-21 23:57:28 发布