Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to control BOM in writing UTF8 files?

807598Apr 27 2006 — edited Sep 5 2008
When I write a text file using UTF8 encoding, the BOM (0xEF0xBB0xBF) is sometimes written to the file, and sometimes not.

Is there any way to control whether to write BOM?

My code is
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("filename.txt"), "UTF-8"))
Thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2008
Added on Apr 27 2006
6 comments
16,283 views