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;
}