writechars in RandomAccessFile
HI,
I have a problem using writechars.
einDatei = new RandomAccessFile("einFile.txt","r");
ausDatei = new RandomAccessFile("ausFile.txt", "rw");
einDatei.seek(0);
s = einDatei.readLine();
ausDatei.writeChars(s);
s = einDatei.readLine();
ausDatei.writeChars(s);
einDatei.close();
ausDatei.close();
einFile.txt looks like :
"Hello World!
Hello world!"
ausFile.txt looks like :
" H e l l ow o r l d ! H e l l ow o r l d ! "
What is wrong?
thanks for help
[564 byte] By [
Thraxasa] at [2007-10-3 4:01:39]

> What is wrong?
Nothing.
readLine() reads a line of text and converts each byte into a
character using 0 as the value for the character's upper 8 bits.
writeChars() uses the writeChar() method. This one writes each
character as a two byte value, high byte first.
So these methods are not the opposite of one another, and you
shouldn't expect to get the same file you started with. Full details in
the API docs: http://java.sun.com/j2se/1.5.0/docs/api/java/io/RandomAccessFile.html
Keep in mind that the Java char is a 16 bit Unicode character.
(http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html)