`
xinyiwust
  • 浏览: 13104 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

如何判断文本是否是UTF8编码

    博客分类:
  • java
阅读更多
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;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics