Get parent directory as a File object, or null if this File object does not have a parent. in Java
Description
The following code shows how to get parent directory as a File object, or null if this File object does not have a parent..
Example
//from w w w . java 2s . com
import java.io.File;
public class Main {
public static void main(String[] a) {
File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java");
System.out.println(myFile.getParentFile());
System.out.println(myFile);
}
}
The code above generates the following result.