判断文件是否UTF-8编码

 

 

判断文件是否UTF-8编码:

对于UTF-8编码格式的文本文件,其前3个字节的值就是-17、-69、-65

 

			InputStream fis = fileItem.getInputStream();
			byte[] buf = new byte[fis.available()];
			fis.read(buf);
			fis.close();
			if (buf[0] == -17 && buf[1] == -69 && buf[2] == -65) {//编码为UTF-8
				String content = new String(buf,"UTF-8");
				//...TODO
			} else {
				throw new BIException("请导入UTF-8编码的文件");
			}

 

 

参考:http://blog.csdn.net/wangpeijiang/article/details/5458033

 

你可能感兴趣的:(utf-8)