Hi All, I am using FileIO. And creating FileReader Object in Java file. as like FileReader aa = new FileReader ("prop.txt"); Giving relative path. If I compile and then make an executables jar (Adding all class files and prop.txt file). And run it then it gives the exception FileNotFoundException. How can I give path in FileReader constructor? Waiting for reply, Regards from Parshuram Walunjkar
Hi Parshuram, If you want to read a file that is packaged in a JAR file, you need to use the "java.util.jar.JarFile" class, it contains the following method: public ZipEntry getEntry(String name) and (I imagine) you would pass "prop.txt" as the parameter. You can then get an "InputStream" for the "prop.txt" file by invoking: public InputStream getInputStream(ZipEntry ze) I suggest you study the documentation ("javadoc") for the "JarFile" class. Hope this has helped you. Good Luck, Avi.
Check out Class.getResource() and Class.getResourceAsStream(). getResourceAsStream() is usually easier because it skips a step and returns an InputStream. Then you can use that input stream to read through your file.
Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"