Just for my interest, I've seen a lot of posts where people can't get an xml file or say a properties file in a war.
new FileInputStream doesn't work but getClass().getResourceAsStream() does, could someone explain succinctly to me why this is the case. What is the difference between these mechanisms that makes the latter work.
Also I've seen posts where the getResourceAsStream() method works for App Servers that expand the war but not for those that don't, why is this and what is the solution that will work in both expanded and non-expanded cases?
Well, the answer is not related so servlets at all, so this topic will probably be moved to I/O. Anyway, the point is that you actually can use a FileInputStream; you just need the complete URL to the file, like "jar:file:/some.war!/your.xml". The tough part -- maybe not that tough, just not trivial -- is to get the war/jar file. Releasing you of the extra effort of getting jar file or finding the exploded path is the purpose of getResourceAsStream() -- as far as I understand it. I thought that getResourceAsStream() would work for both expanded and non-expanded war files, so I don't know what could work for both. Hope this brief answer clarifies a little, and sorry if it didn't. Best regards
Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
subject: getResourcesAsStream Versus new FileInputStream