I have a Netbeans maven project, and am using the src/main/resources
folder to deploy my pictures and a help file alongside the program that I'm writing.
From my understanding of the subject, any files in this folder (and the packages that contain them) are archived in the generated .jar
file generated by the Netbeans IDE. I've verified this by opening the jar in a compressed file extraction program.
This is convenient for deployment, and previously, I ran into issues with versioning, with some pictures being out of date, as I was using folders on the disk to house the pictures folder previously.
I have a subroutine that selects a random picture from the pictures folder, but implementing this inside the jar file clashes with my understanding of the subject.
If the pictures folder is now in the jar archive, how can I get Path
objects to these files? I'm well aware that I can use Clazz.class.getResource("/pictures")
to get a URL object to the folder. I can also transform this URL into a URI and feed it to the File
constructor and use getPath
to get a path to this folder on the disk.
Then I can call Files.list(picturesPath)
; to get the list of Paths and select a random one.
This process would work just fine if the files/folders were just regular files/folders on the disk, but they're not, they're inside a compressed jar archive. This confuses me.
Can I just treat these folders I get back as Path
s as typical folders and manipulate them in the typical way I do regular folders? Is there techno-sorcery at work to make this seamless or is there some subtle fallacy in my assumptions that would prevent me from using something like Files.list(picturesPath)
?