Java File Name Get getFilename(String path)

Here you can find the source of getFilename(String path)

Description

get Filename

License

Creative Commons License

Declaration

public static String getFilename(String path) 

Method Source Code

//package com.java2s;
/**/*from w  ww  .  j av  a 2 s . co  m*/
 * Source: http://stackoverflow.com/questions/453018/number-of-lines-in-a-file-in-java
 * Licensed under http://creativecommons.org/licenses/by-sa/3.0/
 */

import java.io.File;

public class Main {
    public static String getFilename(String path) {
        return getFilename(path, File.separator);
    }

    public static String getFilename(String path, String separator) {
        int filenameStart = path.lastIndexOf(separator);

        if (filenameStart != -1) {
            filenameStart += 1; // move cursor after dot
            return path.substring(filenameStart);
        }

        return path;
    }
}

Related

  1. getFilename(String path)
  2. getFileName(String path)
  3. getFileName(String path)
  4. getFileName(String path)
  5. getFileName(String path)
  6. getFileName(String s)
  7. getFileName(String s)
  8. getFileName(String s)
  9. getFileName(String template, String className, String packageName)