file getName Example
file class getName example. This example shows you how to use getName method.
File class getName example. method returns String representation of thus abstract pathname.after applying the method file or directory name is returned. file is returned with its extension.method is called by a String class object.
Here is the code:-
/**
* @Program uses getName method to get the name of file or
* directory from its abstract path and generates result as string.
* GetName.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class GetName {
public static void main(String args[]) {
File file_name = new File("/tmp/home/codingdiary.html");
File file1_name = new File("/home/Desktop/baadshah.wmv");
String str0 = file_name.getName(), str1 = file1_name.getName();
System.out.println("Name of the file is: " + str0);
System.out.println("Name of the file is: " + str1);
}
} |
Output of the program:-
Name of the file is: codingdiary.html
Name of the file is: baadshah.wmv |
|