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(final String name)
basename
final int colon = name.indexOf(':');
if (colon != -1) {
    return name.substring(colon + 1);
} else {
    return name;
StringbaseName(String controllerName)
base Name
if (controllerName.endsWith(CONTROLLER_SUFFIX)) {
    return controllerName.substring(0, controllerName.length() - CONTROLLER_SUFFIX.length());
return controllerName;
StringbaseName(String filename)
Strip a filename of its last extension (the portion immediately following the last dot character, if any)
int i = filename.lastIndexOf('.');
return (i > -1) ? filename.substring(0, i) : filename;
StringbaseName(String filename)
base Name
return baseName(filename, ".");
Stringbasename(String filename)
basename
String result = filename;
int p = result.lastIndexOf('/');
if (p >= 0) {
    result = result.substring(p + 1);
p = result.lastIndexOf('.');
if (p >= 0) {
    result = result.substring(0, p);
...
StringbaseName(String filename)
Returns the basename of a filename.
if (filename == null)
    return "";
String basename = filename;
int idx = basename.lastIndexOf('/');
if (idx >= 0) {
    idx++;
    if (basename.length() == idx)
        return "";
...
StringbaseName(String fn)
Given a full or partial path name, locate the "base name" from the name.
String separator = System.getProperty("file.separator");
int sepLen = separator.length();
int startPos = fn.length() - sepLen;
if (startPos < 0)
    return "";
int pos;
for (pos = startPos; pos >= 0; pos--) {
    String testChar = fn.substring(pos, pos + sepLen);
...
StringbaseName(String name)
Search for both slashes in order to support URLs and files.
int index = name.lastIndexOf('\\');
if (index < 0) {
    index = name.lastIndexOf('/');
if (index >= 0)
    return name.substring(index + 1);
else {
    int lastColonIndex = name.lastIndexOf(':');
...
Stringbasename(String name, String split)
return String basename
if (name == null || name.equals("")) {
    return "";
if (split == null || split.equals("")) {
    split = ".";
int index = name.lastIndexOf(split);
if (index >= 0) {
...
Stringbasename(String path)
Return the filename portion of a path.
String filename = path.substring(path.lastIndexOf('/') + 1);
if (filename == null || filename.equalsIgnoreCase("")) {
    filename = "";
return filename;