Using getName() and getParent() in java.io.File

Here is the tutorial for using the getName() and getParent() in File.


import java.io.*;
class FileNameParent
{
public static void main(String args[])
{
// Create a file object pointing this file
File f=new File("C:\\java\\FileNameParent.java");
// Print name
System.out.println("The name of the file is "+f.getName());
// Print parent
System.out.println("The parent of this file is "+f.getParent());
}
}
--------------------------------------
Output:
--------------------------------------
The name of the file is FileNameParent.java
The parent of this file is C:\java


Posted by at on

Tags: Java IO,