This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have this embarssing problem, in reading a file which is packaged in a jar file.
I have a project in eclipse, say sample. My project structure is as below
Under this setup, I can simply access the file in Sample.java, as below
and it works like a gem .
Now I exported this project as a runnable jar file and when I looked into the jar file, sample.properties is missing, as expected.
So, in order to have this file available in jar file, I moved sample.properties into src folder. But this time, FileReader fails, as it could not find the file for apparent reasons.
Exception Caused: The property file sample.properties could not be resolv
ed java.io.FileNotFoundException: file:\C:\Projects\Sample.jar!\Sample.properties (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
I know that the way, I'm accessing the file in FileReader is the problem, but not able to fix it. How can access the file when that is the part of the jar file, to which class belongs. This is apparently the most common way of doing where everything is jar'ed together.