I need to copy a folder, packed in a Jar on runtime. I want to do it by calling a function in a class which is also contained in the same folder.
I’ve tried using getSystemResource:
URL sourceDirUrl = ClassLoader.getSystemResource("sourceDirName");
File sourceDir = new File(sourceDirUrl.toURI());
but it doesn’t work.
I probably have to use getResourceAsStream function recursively. Is there a more elegant/strait-forward way to do this?
In case I have to do it recursively:
1. I don’t want to specify the files hard-coded, I want to do it dynamically
2. I don’t want to create a separate archive. I want this resource to be in the same Jar as the classes dealing with it
Thanks
I ended up doing what Koziołek suggested below. Although I was hoping for a more elegant solution, but it looks like this is as good as it gets.
Jar is simple ZIP file. You can use java.util.zip.* package to decompress files.