I am currently working on a program to make sitting charts for my teacher\'s classroom. I have put all of the data files in the jar. These are read in and put in to a table.
Tomasz is right that the following is bad practice, but it is possible.
The contents of the classpath are read into memory during bootstrapping, however the files are modifiable but their changes will not be reflected after initialisation. I would recommend putting the data into another file, separate to your class files, but if you insist on keeping them together, you could look at:
Make sure you're not reading the resource through the classpath and that it's coming from a file on disk / network.
Put data files outside of the binary and ship together with JAR in a separate folder.
It seems like you are approaching the problem from the wrong direction. JAR file is something like an executable (.exe
) on Windows platform - a read only binary containing code.
You can (although it is a bad practice) put some resources like data files, multimedia, etc. inside JAR (like you can inside .exe
). But a better solution would be to place these resources outside of the binary so you can switch them without recompiling/rebuilding.
If you need to modify the resources on-the-fly while the application is running, you basically have no choice. The data files have to be outside the binary. Once again, you'll never see a Windows .exe
file modifying itself while running.