Java Utililty Methods File Name Extract

List of utility methods to do File Name Extract

Description

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

Method

StringextractFileName(final String filePath)
extract File Name
String result;
int pos = filePath.lastIndexOf(fileSeparator);
if (pos < 0) {
    result = filePath;
} else {
    result = filePath.substring(pos + 1, filePath.length());
return result;
...
StringextractFileName(StackTraceElement aFrame)
extract File Name
String fileName = aFrame.getFileName();
if (fileName != null) {
    int atIndex = fileName.indexOf("@");
    if (atIndex != -1) {
        fileName = fileName.substring(0, atIndex);
    return fileName;
} else {
...
StringextractFileName(String file)
extract File Name
if (file.matches("^(\\w){2,}:.*")) 
    return null;
else if (file.matches("^\\/.*")) 
    return file;
else if (file.matches("^\\w:[\\\\,\\/].*")) { 
    file = file.replaceAll("\\\\", "\\/"); 
    return "/" + file; 
} else if (file.matches("^(\\.)+\\/.*|^\\w+\\/.*|^\\w+.*")) 
...
StringextractFileName(String fileName)
extract File Name
if (null == fileName || "".equals(fileName.trim())) {
    throw new IllegalArgumentException("File Name cannot be Null/Empty");
int extensionStartPt = fileName.lastIndexOf(".");
return fileName.substring(0, extensionStartPt);
StringextractFileName(String filePathName)
Extract file name (without path and suffix) from file name with path and suffix.
if (filePathName == null)
    return null;
int dotPos = filePathName.lastIndexOf('.');
int slashPos = filePathName.lastIndexOf('\\');
int backSlashPos = filePathName.lastIndexOf('/');
slashPos = slashPos > backSlashPos ? slashPos : backSlashPos;
if (dotPos > slashPos) {
    return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0, dotPos);
...
StringextractFileName(String filePathName)
extract File Name
if (filePathName == null) {
    return null;
int dotPos = filePathName.lastIndexOf('.');
int slashPos = filePathName.lastIndexOf('\\');
if (slashPos == -1) {
    slashPos = filePathName.lastIndexOf('/');
if (dotPos > slashPos) {
    return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0, dotPos);
return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0);
StringextractFileName(String fn)
extract File Name
int j = lastIndexOfPathSeparator(fn);
if (j == -1) {
    return fn;
return (fn.substring(j + 1));
StringextractFileName(String fullPath)
extract File Name
String sep1 = "/";
String sep2 = "\\";
if (fullPath.lastIndexOf(sep1) >= 0) {
    return fullPath.substring(fullPath.lastIndexOf(sep1) + 1);
} else if (fullPath.lastIndexOf(sep2) >= 0) {
    return fullPath.substring(fullPath.lastIndexOf(sep2) + 1);
return fullPath;
...
StringextractFileName(String name)
extract File Name
return name.substring(0, 8);
StringextractFilename(String path)
extract Filename
if (path == null)
    return null;
String norm = path.replace('\\', '/');
int i = norm.lastIndexOf('/');
if (i == -1) {
    return path;
} else {
    return norm.substring(i + 1);
...