Write a Java Program to Get the name of the file from the absolute path

Write a Java Program to Get the name of the file from the absolute path

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import java.io.File;

class Main {

  public static void main(String[] args) {

    // link to file Test.class
    File file = new File("C:\\Users\\Sudip Bhandari\\Desktop\\Programiz\\Java Article\\Test.class");

    // get file name using getName()
    String fileName = file.getName();
    System.out.println("File Name: " + fileName);

  }
}

Final output

Leave a Comment