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