The standard, portable and recommended way to achieve this in Java EE (I do hope you are using Java EE - though it holds for J2EE too) is to use ClassLoader.getResourceAsStream(String name). The ClassLoader is your app's ClassLoader (which you can obtain e.g. as getClass().getClassLoader()) and the resource name is the absolute path to the resource within your deployment module (i.e. WAR).
↧