0

I have a resources folder/package in the root of my project. All I want to do is to load a "Folder" within the resources folder, loop through the Files inside that Folder and get a Stream to each file and read the content from each file. https://i.stack.imgur.com/aAev6.jpg

I've tried doing this in several different ways and most of them work in the IDE but not when I launch my application from the jar file directly.

For example this code works fine in the IDE :

String data ="/fichier/";
public ArrayList<String> getResources(final String path) throws IOException {
ArrayList<String> retour = new ArrayList<>();
String Line;
final InputStream is = getClass().getResourceAsStream(path);
final InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
final BufferedReader br = new BufferedReader(isr);

while ((Line = br.readLine()) != null) {
    retour.add(Line);
}

return retour;

}
Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45

2 Answers2

0

Add the below block to POM file .

<resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
Ankur Srivastava
  • 855
  • 9
  • 10
0

According to the previous answered question https://stackoverflow.com/a/20073154/2802664

You may try to use JarFile to read the content of jar.

Community
  • 1
  • 1
Robert.Li
  • 169
  • 1
  • 7