I would like to get a list of file contained in a directory which is in a jar package.
I have an "images" folder, within it I have an Images
class that should load all images from that directory.
In the past i used the MyClass.class.getResourceAsStream("filename");
to read files, but how do I read a directory?
This is what I tried:
System.out.println(Images.class.getResource("").getPath());
System.out.println(new File(Images.class.getResource("").getPath()).listFiles());
I tried with Images.class.getResource
because I have to work with File
and there isn't a constructor that accepts an InputStream
.
The code produces
file:/home/k55/Java/MyApp/dist/Package.jar!/MyApp/images/
null
So it is finding the folder which I want to list files from, but it is not able to list files.
I've read on other forums that in fact you can't use this method for folders in a jar archive, so how can I accomplish this?
Update: if possible, i would like to read files without having to use the ZipInputStream