If you want to be able to save the scores again, using getResourceAsStream
isn't really a good idea - that's meant for resources which are bundled with the application, often within a jar file, and often read-only.
You might want to consider using the Java preferences API or work out some specific location for the file to use to store the high scores. Then just write to that file when saving, and read from it while loading. I wouldn't personally use PrintWriter
(it swallows exceptions) or FileWriter
(you can't specify the character encoding), but both should work. You just need to make sure you load the scores from the same file as you save it to. (It's not clear whether /files/highscores.txt
is really an appropriate file to save to... do you have a /files
directory? Were you expecting this to be relative to your application's working directory?)
(Also, it's a good idea to start following Java naming conventions, using camelCasing
for method names... and use a try-with-resources statement to close writers, streams etc when you're finished with them, instead of manually calling close
.)