getName(): Returns the name of the file without the path or the directory name
import java.io.File; public class MainClass { public static void main(String[] a) { File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java"); System.out.println(myFile.getName()); System.out.println(myFile.getPath()); } }
File.java C:\jdk1.5.0\File.java