I need a bit of help trying to figure out an issue I'm having with my program. If I run my program as is in my IDE (before exporting it to an executable JAR) I am able load in a txt file with some values, modify that file by making a temporary copy of it, and then renaming the modified file to the name of the original or source file. However, when I create my JAR, I am only able to load in the original file. There is no way, apparently, to do a write to the source file because the JAR essentially locks down the text file I need to modify.
Now, my question is how can I simulate this copying of the source file, modification, and then renaming of the modified file to the original? Am I thinking about this all wrong? Here is my code I'm using thus far (the deleteFromFile method is where I am stuck in terms of getting this to work with my JAR):
As you've found, you can't update resources which are in a JAR file. So the way to go is to store your modifiable text file somewhere else.
So your question now is, where should you store it? You should store it in the user's home folder, or perhaps in a subfolder of that which is specific to your application. You can find the user's home folder like this:
As for the simulating you asked for, the algorithm is like this:
1. Did you already write a modified version in the user's home folder? If so, read that. If not, use the code you already have to read the resource from the JAR.
2. Write the newly modified version into the user's home folder.