The common BOMs are :
Encoding | Representation (hexadecimal) | Representation (decimal) |
UTF-8 | EF BB BF | 239 187 191 |
UTF-16 (BE) | FE FF | 254 255 |
UTF-16 (LE) | FF FE | 255 254 |
UTF-32 (BE) | 00 00 FE FF | 0 0 254 255 |
UTF-32 (LE) | FF FE 00 00 | 255 254 0 0 |
The sample code
public class Bom{
public static void main(String[] args) throws Exception{
String text = "this is text body";
byte[] tbyte = text.getBytes("UTF-8");
FileOutputStream fos = new FileOutputStream("bom.txt");
fos.write(239);
fos.write(187);
fos.write(191);
fos.write(tbyte);
fos.close();
}
}
Reference:
程序员永远的痛之字符编码的奥秘
http://www.rgagnon.com/javadetails/java-handle-utf8-file-with-bom.html
https://community.oracle.com/thread/1263222
http://blog.csdn.net/tu_bingbing/article/details/7988735