Java Utililty Methods File Naked Name Get

List of utility methods to do File Naked Name Get

Description

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

Method

StringextractFileNameWithoutExt(String filePath)
Extrait un nom de fichier y compris son chemin, mais sans son extension.
int idx = filePath.lastIndexOf(".");
return (idx > -1) ? filePath.substring(0, idx) : filePath;
StringextractFileNameWithSuffix(String filePathName)
Extract file name (without path but with suffix) from file name with path and suffix.
if (filePathName == null)
    return null;
int slashPos = filePathName.lastIndexOf('\\');
if (slashPos == -1)
    slashPos = filePathName.lastIndexOf('/');
return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0);
StringextractFileWithoutExtension(String filename)
extract File Without Extension
try {
    int cutlen = extractFileExtension(filename).length();
    if (cutlen == 0)
        return filename;
    return filename.substring(0, filename.length() - cutlen - 1);
} catch (Exception e) {
    return filename;
StringextractFileWithoutPath(String input)
extract File Without Path
if (input == null) {
    return null;
} else {
    int lastSlashPos = Math.max(input.lastIndexOf('/'), input.lastIndexOf('\\'));
    return (lastSlashPos == -1 ? input : input.substring(lastSlashPos + 1));
StringfileNameWithoutExtension(String filename)
file Name Without Extension
int lastDotIndex = filename.lastIndexOf('.');
char nix_sep = '/';
char win_sep = '\\';
int lastUnixSepIndex = filename.lastIndexOf(nix_sep);
int lastWindowsSepIndex = filename.lastIndexOf(win_sep);
int lastSepIndex = Math.max(lastUnixSepIndex, lastWindowsSepIndex);
int substringIndex = (lastSepIndex > lastDotIndex ? -1 : lastDotIndex);
if (substringIndex < 0) {
...
StringfilenameWithoutExtension(String filename)
filename Without Extension
int pos = filename.lastIndexOf(".");
if (pos < 0) {
    return filename;
return filename.substring(0, pos);
StringgetFilenameNoExt(File f)
Obtin numele fara extensie
String base = null;
String s = f.getPath();
int pos = s.lastIndexOf('.');
int min = s.lastIndexOf('/');
if (pos > min && pos < s.length() - 1) {
    base = s.substring(min + 1, pos);
} else
    return s;
...
StringgetFileNameNoExt(File file)
Removes extension from file name
String filename = file.getName();
return filename.substring(0, filename.lastIndexOf("."));
StringgetFileNameNoExt(String path)
get File Name No Ext
String name = getFileName(path);
int p = name.lastIndexOf('.');
if (p == -1) {
    return name;
return name.substring(0, p);
StringgetFileNameNoExtension(File file)
Get Filename minus it's extension if present
return getFileNameNoExtension(file.getName());