|
Parent Directory
The following example shows how to get parent directory of the given file. You can observe that
the parent directory of root file system is null.
|
package com.bethecoder.tutorials.io;
import java.io.File;
public class ParentDirectory {
/**
* @param args
*/
public static void main(String[] args) {
File directory = new File("C:\\NEW\\NEW_SUB");
System.out.println("Directory : " + directory);
System.out.println("Parent Directory : " +
directory.getParentFile());
System.out.println("Parent Parent Directory : " +
directory.getParentFile().getParentFile());
System.out.println("Parent Parent Parent Directory : " +
directory.getParentFile().getParentFile().getParentFile());
}
}
|
| |
It gives the following output,
Directory : C:\NEW\NEW_SUB
Parent Directory : C:\NEW
Parent Parent Directory : C:\
Parent Parent Parent Directory : null
|
|