Java File Name Get getFileName(String filePath)

Here you can find the source of getFileName(String filePath)

Description

The file name of the specified file path is returned.

License

Open Source License

Parameter

Parameter Description
filePath A file path to return a file name to.

Return

String file name.

Declaration

public static String getFileName(String filePath) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    /**//w ww . ja  v a  2s  .c om
     * The file name of the specified file path is returned.
     *
     * @param filePath A file path to return a file name to.
     * @return String file name.
     */
    public static String getFileName(String filePath) {
        File file = new File(filePath);
        String fileName = file.getName();
        int postion = fileName.lastIndexOf('.');
        if (postion == -1)
            return fileName;
        return fileName.substring(0, postion);
    }
}

Related

  1. getFileName(String f)
  2. getFileName(String fileName)
  3. getFileName(String filePath)
  4. getFileName(String filePath)
  5. getFileName(String filepath)
  6. getFileName(String filePath)
  7. getFileName(String filePath)
  8. getFilename(String filePath)
  9. getFileName(String folder, final String path)