How to write UTF-16 with BOM in little endian Von: Jean-Marc Autexier <[email protected]> Datum: Samst

J

Jean-Marc Autexier

Hi,

I must write UTF-16 files, with byte order mark (BOM) in little endian (jdk
1.4.2).

According to java.nio.charset, UTF-16LE and UTF-16BE don't use BOM, UTF-16
does (as defined in Unicode and XML standards).

UTF-16 can read big and little endian, but can only write big endian (see
below). Why?

regards
Jean-marc


From http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html

- When decoding, the UTF-16BE and UTF-16LE charsets ignore byte-order marks;
- when encoding, they do not write byte-order marks.
- When decoding, the UTF-16 charset interprets a byte-order mark to indicate
the byte order of the stream but defaults to big-endian if there is no
byte-order mark; when encoding, it uses big-endian byte order and writes a
big-endian byte-order mark.
 
R

Roedy Green

- When decoding, the UTF-16BE and UTF-16LE charsets ignore byte-order marks;
- when encoding, they do not write byte-order marks.
- When decoding, the UTF-16 charset interprets a byte-order mark to indicate
the byte order of the stream but defaults to big-endian if there is no
byte-order mark; when encoding, it uses big-endian byte order and writes a
big-endian byte-order mark.


check out http://mindprod.com/jgloss/encoding.html


UnicodeLittle and UnicodeLittleUnmarked should give you what you want.
 
J

Jean-Marc Autexier

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top