Here you can find the source of getFileName(String filePath)
Parameter | Description |
---|---|
filePath | A file path to return a file name to. |
public static String getFileName(String filePath)
//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); } }