Android File Extension Name Get getFileExtensionFromName(String filename)

Here you can find the source of getFileExtensionFromName(String filename)

Description

get File Extension From Name

License

Apache License

Declaration

public static String getFileExtensionFromName(String filename) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String getFileExtensionFromName(String filename) {
        if (filename == null) {
            return null;
        }/*from  w w w.ja  v  a 2 s  .c  om*/
        int index = indexOfExtension(filename);
        if (index == -1) {
            return "";
        } else {
            return filename.substring(index + 1);
        }
    }

    private static int indexOfExtension(String filename) {
        if (filename == null) {
            return -1;
        }
        int extensionPos = filename.lastIndexOf(".");
        int lastSeparator = filename.lastIndexOf("/");
        return (lastSeparator > extensionPos ? -1 : extensionPos);
    }
}

Related

  1. getFileExtByFileName(String fileName)
  2. getFileExtension(String file)
  3. getFileExtension(String fileName)
  4. getFileExtension(String filename)
  5. getFileExtension(String filename, String defExt)
  6. getFileExtensionFromSource(byte[] picHeader)
  7. getFileExtensionFromUrl(String url)
  8. getFilenameExtension(String path)
  9. getNameMinusExtension(File file)