Page 1 of 1

About Question enthuware.ocpjp.v7.2.1714 :

Posted: Wed Sep 18, 2013 8:13 am
by The_Nick
Regarding DataInput and DataOutput implementations, why should I use writeChars over writeUTF? What's the difference between the two?

Thanks in advance.

The_Nick.

Re: About Question enthuware.ocpjp.v7.2.1714 :

Posted: Wed Sep 18, 2013 8:24 am
by admin
The difference is given in the API description itself:

writeChars: Writes every character in the string s, to the output stream, in order, two bytes per character.

writeUTF: Writes two bytes of length information to the output stream, followed by the modified UTF-8 representation of every character in the string s.

So if you want what you've written to be read on machines with a different default character encoding, you should write Strings using UTF.

HTH,
Paul.