0

I want to read a content of the directory (paths to the stored files). Let's say this directory is called "/xml-files", where different xml files are stored.

val xml_folder_2 = getClass.getResource("xml-files")
val dir_path = new File(xml_folder_2.getPath)

But the problem is that it returns a null. However, I have the program where everything works (e.g. Paths.get()), but I want to run the program as a jar file, so only getClass.getResources() might be an option (the problem is described here: Java JAR can't find file)

Does someone have an idea how can I get the names of the files inside "xml-files" directory?

Edit 1: For the time being the first line returns a path to the "target" directory that is generated automatically, instead of the path that is stored inside "resources" directory. Maybe that's the problem why I can't list the files inside the directory?

forvev
  • 5
  • 2
  • Is `xml-files` a directory in your users' disk? Or a package inside your JAR? – Luis Miguel Mejía Suárez Mar 18 '23 at 15:39
  • It's a directory within my scala project. – forvev Mar 18 '23 at 15:41
  • 2
    https://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory https://stackoverflow.com/questions/47775482/getting-the-list-of-filenames-from-resource-folder-when-running-in-jar https://stackoverflow.com/questions/50469600/how-do-you-list-all-files-in-the-resources-folder-java-scala – Luis Miguel Mejía Suárez Mar 18 '23 at 15:44
  • Looks good, but now in my case there is a problem with the path. Namely, I get the path to the "target" directory, instead of "resources" one. – forvev Mar 18 '23 at 16:15

0 Answers0