Android File Extension Name Get getPathExtension(final String path)

Here you can find the source of getPathExtension(final String path)

Description

Returns extension of path without ".".

Parameter

Parameter Description
path path to parse

Return

path extension or null if no extension in given path

Declaration

public static String getPathExtension(final String path) 

Method Source Code

import java.io.File;
import java.io.IOException;
import org.apache.log4j.Logger;

public class Main{
    /**/*from  w w  w  .  j a v a  2 s  . c  o m*/
     * Returns extension of path without ".". For example, png, jpg etc.
     * 
     * @param path
     *            path to parse
     * @return path extension or null if no extension in given path
     */
    public static String getPathExtension(final String path) {
        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;
    }
}

Related

  1. getFileExtensionFromName(String filename)
  2. getFileExtensionFromSource(byte[] picHeader)
  3. getFileExtensionFromUrl(String url)
  4. getFilenameExtension(String path)
  5. getNameMinusExtension(File file)
  6. getSuffix(String f)
  7. hasExtension(String filename, String extension)
  8. indexOfExtension(String filename)
  9. isValidFileExtension(String extension)