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 file)
Returns the file extension of the specified file.
int pos;
String filename;
filename = file.getName();
pos = filename.lastIndexOf('.');
if (pos >= 0) {
    return filename.substring(pos + 1);
} else {
    return "";
...
StringgetFileExtension(File file)
returns the file extension, or empty-string of the file has no extension.
String filePath = file.getPath();
int index = filePath.lastIndexOf(DOT);
if (index >= 0)
    return filePath.substring(index + 1);
else
    return "";
StringgetFileExtension(File file)
get File Extension
String fileName = file.getName();
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0)
    return fileName.substring(fileName.lastIndexOf(".") + 1);
else
    return "";
StringgetFileExtension(File file)
get File Extension
String fileName = file.getAbsolutePath();
String ext = (fileName.lastIndexOf(".") == -1) ? ""
        : fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
return ext;
StringgetFileExtension(File file)
Returns the extension of the file.
return getFileExtension(file.getName());
StringgetFileExtension(File file)
Gets the file extension from a file
if (file == null) {
    return null;
if (!file.getName().contains(".")) {
    return null;
return file.getName().substring(file.getName().lastIndexOf('.') + 1);
StringgetFileExtension(File file)
Get the file extension of a file.
String path = file.toString();
if (path == null) {
    return null;
String fileExtension = path.substring(path.lastIndexOf('.') + 1);
return fileExtension;
StringgetFileExtension(File file)
get File Extension
if (file == null)
    return null;
int extPos = file.getAbsolutePath().lastIndexOf(".");
int sepPos = file.getAbsolutePath().lastIndexOf(File.pathSeparator);
if (extPos == -1)
    return null;
if (sepPos > extPos)
    return null;
...
StringgetFileExtension(File file)
Get the file extension of given file.
String fileName = file.getName();
int position = fileName.lastIndexOf('.');
if (position == -1)
    return null;
return fileName.substring(position + 1);
StringgetFileExtension(File file, boolean includeDot)
get File Extension
return getFileExtension(file.getName(), includeDot);