I want to access my current working directory using java.
My code :
String current = new java.io.File( \".\" ).getCanonicalPath();
System.ou
See: http://docs.oracle.com/javase/tutorial/essential/io/pathOps.html
Using java.nio.file.Path
and java.nio.file.Paths
, you can do the following to show what Java thinks is your current path. This for 7 and on, and uses NIO.
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
System.out.println("Current relative path is: " + s);
This outputs Current relative path is: /Users/george/NetBeansProjects/Tutorials
that in my case is where I ran the class from. Constructing paths in a relative way, by not using a leading separator to indicate you are constructing an absolute path, will use this relative path as the starting point.