/*
Get name of specified file or directory
This Java example shows how to get a name of specified file or directory denoted
by a path using getName method of Java File class.
*/
import java.io.*;
public class GetNameOfFileOrDirectory {
public static void main(String[] args) {
//create file object
File file = new File("C://FileIO//FileDemo.txt");
/*
* To get a name of file or directory denoted by a path, use
* String getName() method of Java File class.
*
* This method returns name of the file or directory denoted by path.
*/
String strFileName = file.getName();
System.out.println("File name is : " + strFileName);
}
}
/*
Output would be
File name is : FileDemo.txt
*/