Re: How to write Unicode
Stefan Ram schrieb:
When writing into a Unicode text file, given that the Stream
encoding was set to ??UTF-8??, what is the proper, best or
canonical way to terminate a line?
Some possibilities are given on the following lines.
printStream.printf( "\n" );
printStream.printf( "%n" );
printStream.print(( char )0x000A );
printStream.print(( char )0x000D );
printStream.print(( char )0x000D ); printStream.print(( char )0x000A );
printStream.print(( char )0x0085 ); // 0x0085 is Unicode ??NEL - next
line??
printStream.print(( char )0x2028 ); // 0x2028 is Unicode ??line
separator??
Thomas Fritsch wrote:
Not to forget
printStream.println();
Lest we forget:
All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.
Assuming that your variable "printStream" is of type "PrintStream", which you
did not aver.
I get a cringe seeing "the Stream encoding was set" - Java IO Streams don't
have encodings. The PrintStream methods use encodings, but the Stream doesn't.
To answer your question, printf()'s "%n" specifies "the platform-specific line
separator", but that has nothing to do with encodings.
--
Lew