2

I have a list of public assets inside the "src/main/resources" folder that looks like this:

public/images/

  • asd1.png
  • asd2.png

I'm trying to list all the files inside the "public/images/" directory, as it is a compiled project using sbt universal:packageBin I'm trying to access the assets using:

val input = getClass.getResourceAsStream("/public/images/")

or

val input = getClass.getResource("/public/images/")

getResourceAsStream returns an empty result and getResource returns a URL object that contains a direct path to the folder but I cannot list anything inside that folder even with new File(getClass.getResource("/public/images/")) as the check for .isDirectory() returns a false as a response or .listFiles() throws an exception.

What is the best way to achieve this?

Alex
  • 1,630
  • 1
  • 20
  • 31
  • Please have a look at https://stackoverflow.com/questions/30640627/how-to-unzip-a-zip-file-using-scala – Chaitanya May 11 '18 at 13:23
  • the resources are already loaded inside the class path so unziping a jar thats already loaded seems waistfull – Alex May 11 '18 at 13:24
  • Does `listFiles` throw an exception, or does it simply return `null`? – Andrey Tyukin May 11 '18 at 14:09
  • 1
    @AndreyTyukin it throws a null pointer as it's not a directory and file doesnt exist, the `new File(getClass.getResource("/public/images/"))` deosnt see whats inside the JAR, I did manage to get it working with "new JarFile()" approach but thats loading a jar as a new resources and scanning whats inside, which is waistfull as the resources are already loaded inside the classpath so logically there should be a way to list these resources or even list all resources inside the already loaded jar – Alex May 11 '18 at 14:19

0 Answers0