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

StringgetFileExtension(File f)
get File Extension
if (f.isFile()) {
    String name = f.getName();
    int pos = name.lastIndexOf(".");
    if (pos != -1) {
        return name.substring(pos + 1, name.length());
return "";
...
StringgetFileExtension(File f)
get File Extension
String ext = null;
String str = f.getName();
int ind = str.lastIndexOf('.');
if (ind > 0 && ind < str.length() - 1) {
    ext = str.substring(ind + 1).toLowerCase();
return ext;
StringgetFileExtension(File file)
Given a File object, return the extension (portion after the final '.'), if any.
if (file == null) {
    return null;
String fileName = file.getName();
int dotPos = fileName.lastIndexOf('.');
return dotPos == -1 ? null : fileName.substring(dotPos + 1);
StringgetFileExtension(File file)
get File Extension
String extension = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf('.') + 1);
return extension;
StringgetFileExtension(File file)
get File Extension
String filename = file.getName();
int extensionIndex = filename.lastIndexOf(".");
String extension;
if (extensionIndex == -1) {
    extension = "";
} else {
    extension = filename.substring(extensionIndex + 1, filename.length());
return extension;
StringgetFileExtension(File file)
Return the file extension.
return file.getName().substring(file.getName().lastIndexOf(".") + 1);
StringgetFileExtension(File file)
Returns the extension of the file.
String name = file.getName();
int posLastDot = name.lastIndexOf('.');
if (posLastDot < 0) {
    return null;
return name.substring(posLastDot + 1);
StringgetFileExtension(File file)
get File Extension
if (file.isFile())
    return getFileExtension(file.getName());
else
    return "" + File.separatorChar;
StringgetFileExtension(File file)
Get the file extension of a file
if (file != null) {
    String fileName = file.getName();
    if (fileName.lastIndexOf(".") != -1) {
        String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
        return extension;
    } else {
        return "";
} else {
    return null;
StringgetFileExtension(File file)
Returns the extension of a file or null if the file does not have one (no .
String name = file.getName();
int pos = name.lastIndexOf('.');
String extension = ((pos >= 0) && (pos < name.length() - 1)) ? name.substring(pos + 1).trim().toLowerCase()
        : null;
return extension;