I want to access my current working directory using java.
My code :
String current = new java.io.File( \".\" ).getCanonicalPath();
System.ou
This will give you the path of your current working directory:
Path path = FileSystems.getDefault().getPath(".");
And this will give you the path to a file called "Foo.txt" in the working directory:
Path path = FileSystems.getDefault().getPath("Foo.txt");
Edit : To obtain an absolute path of current directory:
Path path = FileSystems.getDefault().getPath(".").toAbsolutePath();
* Update * To get current working directory:
Path path = FileSystems.getDefault().getPath("").toAbsolutePath();