public class CurrentDirectoryExample {
public static void main(String args[]) {
String current = System.getProperty("user.dir");
System.out.println("Current working directory in Java : " + current);
}
}
If you run above program from C:\Test it will print C:\Test as current working directory
C:\Test> java CurrentWorkingDirectoryExample
Current working directory in Java : C:\Test
If you run it from C:\ then it will print C:\ as current working directory as shown in below example
C:\> java -cp ./Test CurrentWorkingDirectoryExample
Current working directory in Java : C:\
public static void main(String args[]) {
String current = System.getProperty("user.dir");
System.out.println("Current working directory in Java : " + current);
}
}
If you run above program from C:\Test it will print C:\Test as current working directory
C:\Test> java CurrentWorkingDirectoryExample
Current working directory in Java : C:\Test
If you run it from C:\ then it will print C:\ as current working directory as shown in below example
C:\> java -cp ./Test CurrentWorkingDirectoryExample
Current working directory in Java : C:\
No comments:
Post a Comment