public static String getName(String pathAndName) {
        int i = pathAndName.lastIndexOf('/');
        int l = pathAndName.length();
        if (i == -1) {
            return pathAndName;
        } else if (l == i) {
            return "/";
        } else {
            return pathAndName.substring(i + 1);
        }
    }
public static String getName ( String pathAndName ) { int i = pathAndName . lastIndexOf ( '/' ) ; int l = pathAndName . length ( ) ; if ( i == - 1 ) { return pathAndName ; } else if ( l == i ) { return "/" ; } else { return pathAndName . substring ( i + 1 ) ; } }
Answer the last file name of a path, using the forward slash ('/') as the
path separator character. Answer the path element which follows the last
forward slash of the path.

Answer the entire path if the path contains no path separator.

For example:

For "/parent/child" answer "child".

For "child" answer "child".

An exception will be thrown if the path ends with a trailing slash.

@param path The path from which to answer the last file name.

@return The last file name of the path.