JAVA 判断TXT文件编码格式
2013-12-19 09:50
239 查看
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 Map.get(key)类型判断空
- java-判断一个自然数是否是某个数的平方。当然不能使用开方运算
- java 判断一个二叉树是不是平衡二叉树
- java判断一个字符串是否是回文
- java判断某个字符串包含某个字符串的个数
- android、Java下判断两个String是否相等 、EditText输入是否为空,
- 【java web】实现判断是由手机访问还是由电脑访问
- java判断字符串是否为日期格式
- Java中判断字符串是否为数字的方法
- Java判断文件夹是否存在,不存在就创建
- Java实现二叉树(平衡树/搜索二叉树的判断)
- java解析Excel存储-对单元格内容判断
- 用 JAVA 判断一个URL是否有效--CTO
- java判断某时间是否在一个时间段
- 数据结构与算法分析笔记与总结(java实现)--链表15:链表回文判断问题
- Java: 如何判断string or char是否是数字
- Java 判断文件夹、文件是否存在、否则创建文件夹
- Java学习-用正则表达式判断email是否合法
- Java--判断两个文件是否相同
- 在Java中如何高效判断数组中是否包含某个元素