1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/* 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 */ |
Add Comment