Thursday, September 24, 2009

Java - find the working directory

import java.util.*;
public class Main {
    public static void main(String[] args) {
        // to find out where your application is running 
        //  (sounds easy but its sometimes tricky) 
        System.out.println("This Java applications working directory is:");
        // Java has a list of Properties that it uses for everything 
        // the working directory property is user.dir 
        // you can check it out with: 
        // you can see all the properties with this: 
        // it will just dump them all out in a not 
        //  organized way 
        // you can also iterate through all of the properties 
        //  and print them out line by linewith: 
        Properties myProps = System.getProperties();
        for (Enumeration e = myProps.keys(); e.hasMoreElements();/**/){
            String key = (String)e.nextElement();
            String value = myProps.getProperty(key);
            System.out.println(key + " = " + value);

No comments:

Post a Comment