您的位置:首页 > 编程语言 > Java开发

java中获取TXT文件编码格式

2013-12-19 09:55 459 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: