File GetParentFile() Example
Returns the abstract pathname of this abstract pathname's parent
File class GetParentFile() method example. This example shows you how to use GetParentFile method.This method Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.
Here is the code:-
/**
* @Program that Returns the abstract pathname of this abstract pathname's parent
* GetParentFile.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class GetParentFile {
public static void main(String[] args) throws IOException {
File f = new File("/home/girish/Desktop/g.txt");
if (f.exists()) {
File f1 = f.getParentFile();
System.out.println("the pathname's parent is: " + f1);
} else {
System.out.println("File does not exists");
}
}
} |
Output of the Program
| the pathname's parent is: /home/girish/Desktop |
|