首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java稽查文本文件编码格式

2012-11-08 
java检查文本文件编码格式public static String getEncoding(File file) {String encoding GBKFileIn

java检查文本文件编码格式

public static String getEncoding(File file) {String encoding = "GBK";FileInputStream fileInputStream = null;try {fileInputStream = new FileInputStream(file);byte[] b = new byte[3];fileInputStream.read(b);if (b[0] == -17 && b[1] == -69 && b[2] == -65) {encoding = "UTF-8";}} catch (Exception e) {e.printStackTrace();} finally {if (null != fileInputStream) {try {fileInputStream.close();} catch (Exception e) {e.printStackTrace();}}}return encoding;}
?

热点排行