Java Utililty Methods File Name Get

List of utility methods to do File Name Get

Description

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

Method

StringgetFileNameWithoutExt(String fileName)
get File Name Without Ext
if (fileName.lastIndexOf(".") == -1)
    return fileName;
return fileName.substring(0, fileName.lastIndexOf("."));
StringgetFileNameWithoutExt(String filePath)
Returns the name of file without path and extension {Category} StringUtil {param} string(fullPath) fullPath: String.
File f = new File(filePath);
String name = f.getName();
int pos = name.lastIndexOf('.');
if (pos > 0) {
    return name.substring(0, pos);
} else {
    return name;
StringgetFileNameWithoutExt(String originPath)
Get the file name without extension, given a complete path.
String name = "";
try {
    String fileName = getFileName(originPath);
    name = fileName.substring(0, fileName.lastIndexOf('.'));
} catch (Exception e) {
    e.printStackTrace();
return name;
...
StringgetFilenameWithoutExtension(File f)
get Filename Without Extension
String filename = f.getName();
int i = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR);
return i >= 0 ? filename.substring(0, i) : filename;
StringgetFileNameWithoutExtension(File file)
Returns name of specified file without its extension.
if (file == null) {
    return null;
String path = file.getName();
int dotAt = path.lastIndexOf('.');
if (dotAt < 0) {
    return null;
return path.substring(0, dotAt);
StringgetFileNameWithoutExtension(File file)
get File Name Without Extension
String fileName = file.getName();
int pos = fileName.lastIndexOf(".");
if (pos > 0) {
    fileName = fileName.substring(0, pos);
return fileName;
StringgetFileNameWithoutExtension(File file)
get File Name Without Extension
String fileName = null;
if (file == null) {
    throw new IllegalArgumentException("file cannot be null");
int fileExtensionIndex = file.getName().lastIndexOf(".");
if (fileExtensionIndex <= 0) {
    return file.getName();
fileName = file.getName().substring(0, fileExtensionIndex);
return fileName;
StringgetFileNameWithoutExtension(File file)
returns a file's name excluding the extension (by default file name extension separator is a period '.')
return getFileExtension(file.getName());
StringgetFileNameWithoutExtension(File file)
get File Name Without Extension
String filename = file.getName().trim();
if (filename.length() == 0)
    return "";
if (filename.charAt(filename.length() - 1) == '.')
    filename = filename.substring(0, filename.length() - 1);
int lastPointIndex = filename.lastIndexOf('.');
if (lastPointIndex < 0)
    return filename;
...
StringgetFileNameWithoutExtension(File file)
get File Name Without Extension
if (file == null)
    return null;
String fileExt = getFileExtension(file);
String fileName = file.getName();
return fileName.substring(0, fileName.length() - fileExt.length() - 1);