Java File Extension Name Get fileExtension(String filename)

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

Description

file Extension

License

Open Source License

Parameter

Parameter Description
filename The name of the file whose extension we want

Declaration

public static String fileExtension(String filename) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /***********************************************************
     * @param filename/*from w  ww . j  a  va  2  s  .c om*/
     *          The name of the file whose extension we want
     ***********************************************************/
    public static String fileExtension(String filename) {
        String extension = "";

        int i = filename.lastIndexOf('.');
        int p = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));

        if (i > p) {
            extension = filename.substring(i + 1);
        }
        return extension;
    }
}

Related

  1. extractExtension(String url)
  2. extractExtensions(String fileName)
  3. fileExt(String name)
  4. fileExt(String url)
  5. fileExtension(CharSequence path)
  6. fileExtension(String path)
  7. getFileExtension(File _file)
  8. getFileExtension(File f)
  9. getFileExtension(File f)