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

StringextractExtension(final String fileName)
Extract the file extension from a string.
final int dotIndex = fileName.lastIndexOf('.');
if (dotIndex != -1) {
    return fileName.substring(dotIndex + 1);
} else {
    return null;
StringextractExtension(String fileName)
Extract the file-extension
String extension = null;
if (fileName == null) {
    extension = "";
} else {
    int place = fileName.lastIndexOf('.');
    if (place >= 0) {
        extension = fileName.substring(place + 1);
    } else {
...
StringextractExtension(String name)
extract Extension
if (name == null)
    return null;
int dot = name.lastIndexOf('.');
if (dot > -1 && dot < name.length() - 1)
    return name.substring(dot + 1, name.length());
else
    return null;
StringextractExtension(String s)
does not include the dot.
int index = s.lastIndexOf(".");
if (index < 0)
    return "";
return s.substring(index + 1, s.length());
StringextractExtension(String strFilename)
Extracts file extension from filename.
return extractExtension(strFilename, "xml");
StringextractExtension(String url)
Extract the extension from the given URL.
int index = url.lastIndexOf('/');
if (index != -1) {
    url = url.substring(index + 1);
index = url.lastIndexOf('.');
if (index == -1) {
    return null;
url = url.substring(index + 1);
int end = url.indexOf('?');
if (end != -1) {
    url = url.substring(0, end);
end = url.indexOf('#');
if (end != -1) {
    url = url.substring(0, end);
return url;
StringextractExtensions(String fileName)
extract Extensions
int pos = fileName.lastIndexOf(".");
if (pos == -1)
    return "";
return fileName.substring(fileName.lastIndexOf("."));
StringfileExt(String name)
Return filename extension.
String ext = null;
String fname = pathName(name);
int index = fname.indexOf(".");
if (index > 0)
    ext = fname.substring(index, fname.length());
return ext;
StringfileExt(String url)
file Ext
String ext = url.substring(url.lastIndexOf("."));
if (ext.contains("?")) {
    ext = ext.substring(0, ext.indexOf("?"));
if (ext.contains("%")) {
    ext = ext.substring(0, ext.indexOf("%"));
return ext;
...
StringfileExtension(CharSequence path)
Given a file name, this method checks to see if path ends with an extension such as ".java", ".yml", etc.
int index = findExtension(path);
if (index >= 0) {
    return path.subSequence(index, path.length()).toString();
return null;