file getParent Example
file class getParent example. This example shows you how to use getParent method.
File class getParent example. method generates string representations of concerned root directories of file or directory passed in the end of abstract pathname.method is called by a String class object.
Here is the code:-
/**
* @Program uses getParent method to get parent or main
* root directories of files or directories.
* GetParent.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class GetParent {
public static void main(String args[]) {
File parent0 = new File("CanWrite.class");
File parent1 = new File("/home/mahendra/baadshah/IsDirectory.java");
String vip0 = parent0.getParent(), vip1 = parent1.getParent();
System.out.println("Parent names");
System.out.println(vip0);
System.out.println(vip1);
}
} |
Output of the program:-
Parent names
null
/home/mahendra/baadshah |
|