I added code tags to your output and I think it looks better. What you do is put code tags round the text as normal and then change [code=java] to [code=text].
Have you come across a Formatter for your file? You can use that both to write to a text file and to format the output as you go. Look in the
Java Tutorials.