new line in Random Access File in java

aceBox picture aceBox · Jan 30, 2013 · Viewed 13.1k times · Source

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

Marc Baumbach picture Marc Baumbach · Jan 30, 2013

You can write a line separator. In order to get the correct line separator for the currently running operating system, you'll have to look for the line.separator property. Something along these lines:

randomAccessFile.writeBytes(System.getProperty("line.separator"));