Android 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(String file)
get File Extension
String extension = "";
String fileName = new File(file).getName();
int idxOfDot = fileName.lastIndexOf('.');
if (idxOfDot != -1) {
    extension = fileName.substring(idxOfDot + 1);
return extension;
StringgetFileExtension(String fileName)
get File Extension
int index = fileName.lastIndexOf(".");
if (index == -1)
    return null;
return fileName.substring(index + 1);
StringgetFileExtension(String filename)
get File Extension
return getFileExtension(filename, "");
StringgetFileExtension(String filename, String defExt)
get File Extension
if (filename == null || filename.length() == 0)
    return defExt;
int pos = filename.lastIndexOf('.');
if (pos >= 0) {
    return filename.substring(pos + 1);
return defExt;
StringgetFileExtensionFromName(String filename)
get File Extension From Name
if (filename == null) {
    return null;
int index = indexOfExtension(filename);
if (index == -1) {
    return "";
} else {
    return filename.substring(index + 1);
...
StringgetFileExtensionFromSource(byte[] picHeader)
get File Extension From Source
String picExtendName = null;
if (picHeader.length >= 2 && (picHeader[0] == 66)
        && (picHeader[1] == 77)) {
    picExtendName = "BMP";
} else if (picHeader.length >= 4 && (picHeader[1] == 80)
        && (picHeader[2] == 78) && (picHeader[3] == 71)) {
    picExtendName = "PNG";
} else if (picHeader.length >= 6 && (picHeader[0] == 71)
...
StringgetFileExtensionFromUrl(String url)
Returns the file extension or an empty string if there is no extension.
if (url != null && url.length() > 0) {
    int query = url.lastIndexOf('?');
    if (query > 0) {
        url = url.substring(0, query);
    int filenamePos = url.lastIndexOf('/');
    String filename = 0 <= filenamePos ? url
            .substring(filenamePos + 1) : url;
...
StringgetFilenameExtension(String path)
get Filename Extension
if (path == null) {
    return null;
int extIndex = path.lastIndexOf(EXTENSION_SEPARATOR);
if (extIndex == -1) {
    return null;
int folderIndex = path.lastIndexOf(FOLDER_SEPARATOR);
...
StringgetNameMinusExtension(File file)
Returns the file's name minus any extension, that is, the part of its name up to (but not including) the last '.'
Check.arg().notNull(file);
String name = file.getName();
int indexPeriod = name.lastIndexOf('.');
if (indexPeriod == -1)
    return name;
else
    return name.substring(0, indexPeriod);
StringgetPathExtension(final String path)
Returns extension of path without ".".
String result = null;
if (path != null) {
    result = "";
    if (path.lastIndexOf('.') != -1) {
        result = path.substring(path.lastIndexOf('.'));
        if (result.startsWith(".")) {
            result = result.substring(1);
return result;