Java Utililty Methods File Extension Name Extract

List of utility methods to do File Extension Name Extract

Description

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

Method

StringextractFileExt(String _sFilePathName)
extract File Ext
int nPos = _sFilePathName.lastIndexOf('.');
return nPos < 0 ? "" : _sFilePathName.substring(nPos + 1);
StringextractFileExt(String filePath)
Extrait l'extension du nom (ex: .xls) comprise dans un nom de fichier.
int idx = filePath.lastIndexOf(".");
return (idx > -1) ? filePath.substring(idx) : "";
StringExtractFileExtension(String file_name)
Extracts the file extension
int pos = file_name.lastIndexOf(FILE_EXTENSION_SEPARATOR);
if (pos != -1)
    return file_name.substring(pos + 1);
else
    return "";
StringextractFileExtension(String filename)
Extracts file extension (leaves last segment only)
if (filename == null || filename.isEmpty())
    return filename;
int pos = filename.lastIndexOf('.');
if (pos >= 0) {
    return filename.substring(pos + 1);
return null;
StringextractFileExtension(String filename)
extract File Extension
int lastslash = filename.lastIndexOf("/");
if (lastslash != -1)
    filename = filename.substring(lastslash + 1);
lastslash = filename.lastIndexOf("\\");
if (lastslash != -1)
    filename = filename.substring(lastslash + 1);
int lastdot = filename.lastIndexOf(".");
if (lastdot != -1)
...
StringextractFileExtension(String fileName)
extract File Extension
if (null == fileName || "".equals(fileName.trim())) {
    throw new IllegalArgumentException("File Name cannot be Null/Empty");
int extensionStartPt = fileName.lastIndexOf(".");
return fileName.substring(extensionStartPt + 1);
StringextractFileExtension(String filename)
extract File Extension
if (filename.isEmpty())
    return null;
if (filename.contains("/"))
    filename = filename.substring(filename.lastIndexOf("/") + 1);
if (filename.length() < 3 || !filename.contains(".")) {
    return null;
return filename.substring(filename.lastIndexOf('.') + 1);
...
StringextractFileExtension(String filename)
Extracts the file extension of the given file filename or empty string, if no file extension is available.
final int position = filename.lastIndexOf('.');
if (position > 0) {
    return filename.substring(position + 1);
} else
    return "";
StringextractFileExtension(String fileName)
extract File Extension
int extensionIndex = fileName.lastIndexOf(FileExtensionSeperator);
if (extensionIndex == -1) {
    return "";
} else {
    return fileName.substring(extensionIndex, fileName.length());
StringextractFileExtension(String filePath)
extract File Extension
int index = filePath.lastIndexOf(".");
if (index == -1) {
    throw new IllegalArgumentException("no extension for file path..." + filePath);
return filePath.substring(index + 1);