判断文本内容编码格式
//获取编码格式 gb2312,UTF-16,UTF-8,Unicode,UTF-8
public static String getCode(String path) throws Exception { InputStream inputStream = new FileInputStream(path); byte[] head = new byte[3]; inputStream.read(head); String code = "GBK"; // 或gb2312 if (head[0] == -1 && head[1] == -2) code = "UTF-16"; else if (head[0] == -2 && head[1] == -1) code = "Unicode"; else if (head[0] == -17 && head[1] == -69 && head[2] == -65) code = "UTF-8"; inputStream.close(); return code; }