The client code needs to know what is the parrent directory.
The file system (both Linux/Unix and Windows) use the special directory name .. (two dots) as a reference to the current directory. We can use the getCanonicalPath() method found in File class to retrieve the directory name.
The following Java class ParentDir exposes only one public service, the getParentDir() method.
import java.io.File; import java.io.IOException; class parentDir { public static String getParentDir() throws IOException { File dir = new File(".."); return dir.getCanonicalPath(); } }
See also: How To: Find the Current Directory in Java
Back to Java How To