Tuesday, November 11, 2014

Find current directory in standalone Java Program

Sometimes, we have to load a properties file in a Java Program and specially when you have to export a Jar file out of the Java Project, this becomes little difficult. The reason is, depending upon how you run your Java Application, the default directory changes. For an example, if you run it from command-line, it looks under current directory from where you are running the app. But in eclipse, its looks under Project folder (where .classpath file resides). In order to find default directory in Java Program, we can execute following line of code:

                   System.getProperty("user-dir");

This will give you default directory under your current runtime environment.


No comments:

Post a Comment