1

I have a Java console applicaton with a resources folder. It works OK, but when I want to export my code to a runnable Jar file(with Eclipse), then the exported Jar can not find the files(they are in buildpath) and give a Filenotfound exception.

When I unzip the exported Jar file I can see the files are there in the root folder, so I guess something wrong with my code.

BufferedReader srcFile = new BufferedReader(new FileReader("resources/"+filename));
String line = srcFile.readLine();

I tried to use

URL url= ClassLoader.getSystemResource(filename);
filename=url.tostring();        

But no luck.

Spring
  • 11,333
  • 29
  • 116
  • 185

1 Answers1

3

Use getResourceAsStream(String) (docs) if you want to read in a resource on the classpath.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302