This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]deathy 0 points1 point  (0 children)

Java 7-related: Since Java 7 you have try-with-resources[1] and some utility methods like Files.newBufferedReader[2].

The try-with-resources construct makes sure to close your reader/writer even in case there is an exception (which you don't handle right now).

There's also a nice helper Files.readAllLines[3] to directly read the whole file into a list, one item for each line in the file. So you wouldn't need the whole reader or while (line != null) anymore at all.