Java Utililty Methods File Base Name Get

List of utility methods to do File Base Name Get

Description

The list of methods to do File Base Name Get are organized into topic(s).

Method

Stringbasename(String path)
basename
if (path == null)
    return "";
path = path.replaceAll("/+$", "");
int i = path.lastIndexOf('/');
return (path.isEmpty()) ? "/" : (i == -1) ? path : path.substring(i + 1);
Stringbasename(String path)
basename
int index = path.lastIndexOf('/');
if (index == -1) {
    throw new IllegalArgumentException("path does not contain '/'");
return path.substring(index + 1);
Stringbasename(String path)
basename
return path.substring(path.lastIndexOf(PATH_SEP) + 1);
StringbaseName(String path)
Strips directory names and the query-string from a path.
int begin = path.lastIndexOf('/') + 1;
int end = path.indexOf(';');
if (end == -1) {
    end = path.indexOf('?');
    if (end == -1) {
        end = path.length();
return path.substring(begin, end);
Stringbasename(String path)
Compute the name of the last part of the path.
return path.substring(path.lastIndexOf('/') + 1);
Stringbasename(String path, char separator)
Strips the directory from a file path (if any) using the specified character as a separator.
if (path.equals("")) {
    return path;
while (path.endsWith(String.valueOf(separator))) {
    path = path.substring(0, path.length() - 1);
int idx = path.lastIndexOf(separator);
return idx == -1 ? path : path.substring(idx + 1);
...
Stringbasename(String s)
basename
int dot = s.lastIndexOf('.');
return s.substring(0, dot);
Stringbasename(String s)
basename
return basename(s, "");
StringbasenamePart(String className)
basename Part
int lastdot = className.lastIndexOf('.');
return (lastdot == -1) ? className : className.substring(lastdot + 1);