BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(...), StandardCharsets.UTF_8));
out.write('\ufeff');
out.write(...);
This correctly writes out 0xEF 0xBB 0xBF to the file, which is the UTF-8 representation of the BOM.
More Related Contents:
- French and Chinese characters are not appearing correctly
- Java : How to determine the correct charset encoding of a stream
- Byte order mark screws up file reading in Java
- How to convert Strings to and from UTF8 byte arrays in Java
- Spring MVC UTF-8 Encoding
- How to Find the Default Charset/Encoding in Java?
- Who sets response content-type in Spring MVC (@ResponseBody)
- What is the default encoding of the JVM?
- How do I convert between ISO-8859-1 and UTF-8 in Java?
- How to check if a String contains only ASCII?
- HttpServletRequest – setCharacterEncoding seems to do nothing
- What is the most accurate encoding detector? [closed]
- JSON character encoding
- Guessing the encoding of text represented as byte[] in Java
- How to reliably guess the encoding between MacRoman, CP1252, Latin1, UTF-8, and ASCII
- Display special characters using System.out.println
- ISO-8859-1 encoding and binary data preservation
- What is the character encoding of String in Java?
- In Java, how to find if first character in a string is upper case without regex
- Unable to change charset from ISO-8859-1 to UTF-8 in glassfish 3.1
- How do I convert a byte array with null terminating character to a String in Java?
- All inclusive Charset to avoid “java.nio.charset.MalformedInputException: Input length = 1”?
- Disabling contextual LOB creation as createClob() method threw error
- UTF-8 text (Hindi) not getting displayed on Browser window or Eclipse console
- JsonParseException : Illegal unquoted character ((CTRL-CHAR, code 10)
- Java: Converting String to and from ByteBuffer and associated problems
- Removing BOM characters using Java [duplicate]
- First character of the reading from the text file :  [duplicate]
- Java compiler platform file encoding problem
- Detect the URI encoding automatically in Tomcat