Current directory of the given file can be extracted through the getCanonicalPath() method of the File class.
import java.io.File;
public class CurrentDir {
public static void main (String args[]) {
File f1 = new File (".");
File f2 = new File ("..");
try {
System.out.println ("Current directory : " + f1.getCanonicalPath());
System.out.println ("Parent directory : " + f2.getCanonicalPath());
}
catch(Exception e) {
e.printStackTrace();
}
}
}