This program goes to rather elaborate lengths -- perhaps inadvertently -- to remove all the newlines from the original files, thereby breaking most of the formatting and probably mangling the text as well. Instead of reading using a RandomAccessFile, read using BufferedReader, which is designed to work with text. Instead of using FileOutputStream, use a PrintWriter, which again is designed to work with text, not binary data as FileOutputStream is. Instead of using write(string.getBytes()), use println(
string), which will put the newline back at the end of the line.
Alternatively, you could avoid reading and writing lines altogether, and simply read the bytes of one file into the new file, and then the other -- i.e.,
That will of course preserve all the newlines as well.