aceBox aceBox - 1 year ago 79
Java Question

new line in Random Access File in java

Whenever using the 'writeBytes' method of

RandomAccessFile
in java,it writes the text in the same line in the file. How can I get to a new line with
RandomAccessFile
only? (No
BufferedReader
).

Answer Source

Try this:

 RandomAccessFile file = new RandomAccessFile("e:\\demo.txt","rw");
 String originalString = "First line \nSeconf line \n";
 String updatedString = originalString.replace("\n","\r\n");
 file.writeBytes(updatedString);