Java File Base Name Get basename(String path)

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

Description

Return the filename portion of a path.

License

Open Source License

Parameter

Parameter Description
path The path to examine

Return

The filename or empty string if the path is empty or null

Declaration

public static String basename(String path) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w w w .j ava 2 s  .  c o  m
     * Return the filename portion of a path. 
     * @param path The path to examine
     * @return The filename or empty string if the path is empty or null
     */
    public static String basename(String path) {
        String filename = path.substring(path.lastIndexOf('/') + 1);

        if (filename == null || filename.equalsIgnoreCase("")) {
            filename = "";
        }
        return filename;
    }
}

Related

  1. basename(String filename)
  2. baseName(String filename)
  3. baseName(String fn)
  4. baseName(String name)
  5. basename(String name, String split)
  6. basename(String path)
  7. basename(String path)
  8. basename(String path)
  9. baseName(String path)