I’m writing a small GUI app that contains some ‘editor’ functionality, and something that I’d like to let users open a few sample text files to test things out quickly. The easiest way of doing this would be to package a separate zip with the appropriate sample files, and have them open them manually; I’d like to make things a little more user-friendly and allow them to pick the files from inside the application and then run them.
So… what do I use? I initially considered .properties but that doesn’t seem terribly well suited for the job…
You can include a resource file right in the jar and then open it as a resource stream in your app. If you’re using Spring, you can inject the resource right into a bean. If not, check out Class.getResourceAsStream(). You just have to be careful about the path you use to get to the resource file.