0

I have a list of files inside a dependency jar resources/files/file1.xml resources/files/file2.xml resources/files/file3.xml ...

I need to populate an object based on those files but I don't know the files names only the directory in that jar. I need to read all of files and there is relationship among those files.

now I tried two ways, neither is working

  1. I can get an InputStream from that directory but how to put InputStream back to files?

  2. I also try to add a method in original dependency jar : Object getData()-- this just directly get files there. Code is working in that dependency jar project. But once it is called as a dependency jar, it can't find files.

Any suggestion?

asker11
  • 3
  • 1
  • Duplicated https://stackoverflow.com/questions/3923129/get-a-list-of-resources-from-classpath-directory – Pegerto May 05 '21 at 23:29
  • Loading "unknown" resources from the Jar is generally a difficult process, as the base lookup APIs are designed to load "known" resources. If you know the Jar file and can open it, you could treat as simple Zip file, but find the said Jar file at runtime is not as easy as it might sound. A "generally" better solution is to have a "master" file, which is know, which contains a list of the other resources, this could be updated at build time, if your requirements require it – MadProgrammer May 05 '21 at 23:36
  • For [example](https://stackoverflow.com/questions/18247669/read-directory-inside-jar-with-inputstreamreader/18247809#18247809) and [example](https://stackoverflow.com/questions/12015747/get-all-images-within-directory-within-jar-file/12015819#12015819) – MadProgrammer May 05 '21 at 23:36

0 Answers0