This content has been marked as final. Show 2 replies
Every time you recursivley call this method, you're creating a new writer and starting at the beginning of the file, overwriting what you wrote before. Several points:
1) You don't want a RandomAccessFile here, just a FileWriter, wrapped by a PrintWriter and/or BufferedWriter.
2) If you're going to reopen and close the file on every entry to the method, then you want to use the FileWriter constructor that takes a boolean and pass it true, meaning append to the end, rather than overwrite.
3) But don't open/close every time. Just open once before you start iterating and close it when you're all done.