Java Utililty Methods File Extension Name Get

List of utility methods to do File Extension Name Get

Description

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

Method

StringfileExtension(String filename)
file Extension
String extension = "";
int i = filename.lastIndexOf('.');
int p = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
if (i > p) {
    extension = filename.substring(i + 1);
return extension;
StringfileExtension(String path)
file Extension
int token = path.lastIndexOf(".");
String ext = path.substring(token + 1, path.length()).toLowerCase();
return ext;
StringgetFileExtension(File _file)
Extracts the file extension (part behind last dot of a filename).
return getFileExtension(_file.getAbsolutePath());
StringgetFileExtension(File f)
get File Extension
String[] split = f.getName().split("\\.");
if (split.length > 1) {
    return split[1];
} else {
    return null;
StringgetFileExtension(File f)
Get the file extension (if present).
return getFileExtension(f.getName());
StringgetFileExtension(File f)
get File Extension
return getFileExtension(f.getAbsolutePath());
StringgetFileExtension(File f)
Returns file's extension.
String name = (f != null) ? f.getName() : null;
if ((name == null) || (name.length() == 0)) {
    return "";
int pos = name.lastIndexOf('.');
return ((pos > 0) && (pos < (name.length() - 1))) ? name.substring(pos) : "";
StringgetFileExtension(File f)
Return the file extension (the last part of the name after the last '.').
if (f == null)
    return null;
String fn = f.getName();
if (fn.length() <= 0 || fn.startsWith(".")) 
    return fn;
int p = fn.lastIndexOf('.');
if (p < 0)
    return "";
...
StringgetFileExtension(File f)
Gets the file extension.
String result;
if (f.isDirectory())
    result = null;
else {
    int index = f.getName().lastIndexOf('.');
    result = index < 0 || index + 1 == f.getName().length() ? "" : f.getName().substring(index + 1); 
return result;
...
StringgetFileExtension(File f)
Utility function to return the lower-cased file extension - the part of the filename after the last period.
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
    ext = s.substring(i + 1).toLowerCase();
return ext;