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

FilechangeExtension(File file, String extensionNew)
Trys to change file's extension to extensionNew.
Check.arg().validFile(file);
Check.arg().notBlank(extensionNew);
if (extensionNew.contains("."))
    throw new IllegalArgumentException("extensionNew = "
            + extensionNew + " contains a '.' char");
File parent = file.getParentFile();
String nameNew = getNameMinusExtension(file) + "." + extensionNew;
File fileNew = new File(parent, nameNew);
...
StringgetExtension(File file)
Returns the file's extension, defined here as the part of its name after the last '.'
return getExtension(file, false, false);
StringgetExtension(File file)
get Extension
int startIndex = file.getName().lastIndexOf(46) + 1;
int endIndex = file.getName().length();
return file.getName().substring(startIndex, endIndex);
StringgetExtension(File file, boolean useFirstPeriod, boolean includePeriod)
Returns the file's extension.
Check.arg().notNull(file);
String name = file.getName();
int indexPeriod = useFirstPeriod ? name.indexOf('.') : name
        .lastIndexOf('.');
if (indexPeriod == -1)
    return "";
if (!includePeriod)
    indexPeriod += 1;
...
StringgetExtension(String file)
get Extension
int extPos = file.lastIndexOf('.');
if (extPos != -1 && extPos > file.indexOf(File.separatorChar)) {
    return file.substring(extPos);
return "";
StringgetExtension(String filename)
Return the file extension of the provided filename, or null if one does not exist.
if (Util.isBlank(filename)) {
    return null;
if (filename.lastIndexOf('.') == -1) {
    return null;
return filename.substring(filename.lastIndexOf('.') + 1);
StringgetExtensionName(String fileName)
get Extension Name
if ((fileName != null) && (fileName.length() > 0)) {
    int dot = fileName.lastIndexOf('.');
    if ((dot > -1) && (dot < (fileName.length() - 1))) {
        return fileName.substring(dot + 1).toLowerCase();
return "";
StringgetFileEx(String filePath)
get File Ex
String result = null;
int index = filePath.lastIndexOf(".");
if (index > -1) {
    result = filePath.substring(index + 1, filePath.length());
} else {
    result = "noEx";
return result;
...
StringgetFileExt(String fileFullName)
get File Ext
int dot = fileFullName.lastIndexOf(".");
if ((dot > -1) && (dot < fileFullName.length() - 1)) {
    return fileFullName.substring(dot + 1);
} else {
    return null;
StringgetFileExtByFileName(String fileName)
get File Ext By File Name
if (fileName == null)
    return "";
else {
    int idx = fileName.lastIndexOf(".");
    if (idx != -1)
        return fileName.substring(idx + 1);
    else
        return "";
...