UTF8格式的文本开头的三个字节是-17、-69和-65,主要读取文件或流的前三个字节,然后比对即可:
/**
* @param byte0 the first byte of file(or stream)
* @param byte1 the second byte of file(or stream)
* @param byte2 the third byte of file(or stream)
* @return return true if file(or stream) is coded by UTF8,else return false
*/
public static boolean isUTF8(byte byte0,byte byte1,byte byte2){
if(-17 == byte0 && -69 == byte1 && -65 == byte2)
return true;
return false;
}
解读UTF8文件开头字节判断方法
本文详细解析了如何通过读取文件或流的前三个字节来判断其是否使用UTF8编码的方法,提供了实用的代码示例。
303

被折叠的 条评论
为什么被折叠?



