Hi All, I’m back from loooong vacation. Actually haven’t done anything great to blog about, only update is, I switched the company…
Here is recent Java trick I found and I think I should share it..
Problem: I’m wondering about how can I read the file which is in the same directory of my executable JAR ?
[Edited: Read the comment to get easy and obvious answer :)]
Solution: Its simple, just get the current directory and append the file you want to access whose path is relevant to the JAR. Like
In order to read the “my.properties”, I just used the following code.
Simple.
Here is recent Java trick I found and I think I should share it..
Problem: I’m wondering about how can I read the file which is in the same directory of my executable JAR ?
[Edited: Read the comment to get easy and obvious answer :)]
Solution: Its simple, just get the current directory and append the file you want to access whose path is relevant to the JAR. Like
/mydir/Myjar.jar
/mydir/my.properties
In order to read the “my.properties”, I just used the following code.
FileReader reader = new FileReader(new File(new File(“.”), “my.properties”));
Simple.
Comments
That just realizes me the importance of "thinking and keeping things simple". An agile way ;)