• Post Reply Bookmark Topic Watch Topic
  • New Topic

class.getResourcesAsStream couldn't find a specific type of file resource  RSS feed

Wei Lau
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building this maven (web) project, one of the components is to load some files from my src/main/resources/, the first thing is to load all possible files in that folder by using
getResourcesAsStream. I googled and find that you can do so by :
InputStream testIS = getClass().getResourceAsStream("/");
if (testIS != null) {
BufferedReader rdr = new BufferedReader(new InputStreamReader(testIS));

//read all available models
while ((name = rdr.readLine()) != null ) {
InputStream is = getClass().getResourceAsStream("/"+name);
//do your thing here


when I run / test this class it works, it can find all the files without any problem - the src/main/resrouces have text files, binary files etc. e.g.

However, things get interesting when I was calling this jar from another project.
It wouldn't find some of the files, when I debug I can see the while loop ends before the .bin files - as if they are not there!
to verify this, I then change my code from
InputStream testIS = getClass().getResourceAsStream("/");
InputStream testIS = getClass().getResourceAsStream("/model2.bin");

and by doing this it can find this file without a problem, so something must be going on with this line:
InputStream testIS = getClass().getResourceAsStream("/");

but I can't just named all the files in the resrouces folder as it may change frequently.


any ideas?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!