Hi I've always read that readers and writers are specialised in performing input and output of Unicode characters, such that they perform the required conversion to UTF format. However, what I don't understand is why there exists a writeUTF(String s) in the DataOutputStream, which should be more concerned with bytes ....
Hi Martin, The writeUTF() method does write out bytes. See the API
First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for the character. If no exception is thrown, the counter written is incremented by the total number of bytes written to the output stream. This will be at least two plus the length of str, and at most two plus thrice the length of str.
------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
Thanks Jane, It has all become clear. The writeUTF method is fixed to use the UTF-8 encoding mechanism to convert a character to a byte. However, the Writer mechanism (eg file writer) gives the programmer the ability to specify the encoding strategy to use. Superb! Nice day for a walk.
Martin
Do not threaten THIS beaver! Not even with this tiny ad: