I normally use the "getResource" or "getResourceAsStream" method to read configuration files and other data files that I store in jar files. This will search for the file name using anything in your CLASSPATH including any jar's included in your CLASSPATH. It will not guarantee reading from a particular jar if you have multiple jars in your CLASSPATH or directories in your CLASSPATH which contain the same file. In that case, the first one found will be used.
"Jason R. Kretzer" wrote:
Hello everyone, I have a jar that needs to perform an operation on itself(like read a text file inside itself). This is easy enough, however, here is the catch. How can a jar determine what its own file name is? This will need to be determined at runtime. eg. 1.) foo.jar is created using the JDK jar tool.