Public void Test () throws exception{
File File = new file ("C:/test.log");
Randomaccessfile RF = new randomaccessfile (file, "RW");
long filelength = Rf.length ();
Move this pointer to the end of the text
Rf.seek (filelength);
Text file append text, line feed
Rf.writebytes ("11111/n");
Rf.writebytes ("1111/r/n")
Rf.close ();
}
Rf.writebytes ("11111/n");
The program executes the above statement:
There are a lot of small black blocks in the text file, because there is only one character in the file,
That is, 10 of the ASCII code, and in Windows, the newline is represented by two characters, that is, the carriage return plus line, which is 13 and 10 of the ASCII code.
When you open such a file,
Because in this file only newline, no return, so the Notepad program to parse it into a small black block.
Solution:
System.out.println (System.getproperty ("Line.separator"). Length ());//2
String str = system.getproperty ("Line.separator");
for (int i=0;i<str.length (); i++)
Print ASCII Code
System.out.print ((int) Str.charat (i) + ""); 13 10
System.out.println ();
---------------------------------------------
long filelength = Rf.length ();
String lineseparator = System.getproperty ("Line.separator");
Rf.writebytes ("11111" +lineseparator);
First execution filelength = 0
Second execution Filelength = = 7//11111 + "/r/n"
---------------------------------------------------------------------
Third execution filelength = 14
System.getproperty in Java ("Line.separator"). Length () = 2
Writing characters to a text file