vrijdag 12 augustus 2011

getClass().getResource(filename) doesn't work if file is still in jar

I was moving an application from Tomcat to Weblogic and by default in Tomcat the jar/war is extracted whereas in Weblogic this isn't at least not in our setup.

So my code to read a file within my applications classpath was not longer working.

initial code:
URL input = getClass().getResource(queryFileName);
File file = new File(input.getFile());

However the file is not null it's not readable and throws a FileNotFoundException

new code:
InputStream stream;
stream = getClass().getResourceAsStream(queryFileName);

The only disadvantage is you have an InputStream instead of a file.


1 opmerking:

  1. The 13 Best Mobile Casinos That You Can Trust | JtmHub
    Casinos 안동 출장안마 That Make Money Online — The Best Mobile Casinos 대구광역 출장마사지 That You Can Trust. You can find 부산광역 출장마사지 the best mobile casinos 밀양 출장샵 that are 춘천 출장샵 easy to use and

    BeantwoordenVerwijderen