Here you can find the source of getFileName(String filePath)
Parameter | Description |
---|---|
filePath | a parameter |
public static String getFileName(String filePath)
//package com.java2s; import java.io.*; public class Main { /**/*from w w w. ja v a 2 s . c o m*/ * get the file displayName from a file path; * @param filePath * @return */ public static String getFileName(String filePath) { if (filePath == null) { return null; } else { int index = filePath.lastIndexOf('\\'); if (index >= 0) { return filePath.substring(index + 1); } else { index = filePath.lastIndexOf('/'); if (index >= 0) { return filePath.substring(index + 1); } else { return filePath; } } } } /** * get the displayName of a file; not including the file's path; * * @param file * @return */ public static String getFileName(File file) { if (file == null) { return null; } else { return getFileName(file.getAbsolutePath()); } } }