Java File Extension Name Get getFileExtension(File f)

Here you can find the source of getFileExtension(File f)

Description

Utility function to return the lower-cased file extension - the part of the filename after the last period.

License

BSD License

Parameter

Parameter Description
f The file

Return

The file extension in lower case, or null if none exists.

Declaration

public static String getFileExtension(File f) 

Method Source Code

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

import java.io.File;

public class Main {
    /**/*from   w  w w . j a  v a 2  s  .  c o m*/
       * Utility function to return the lower-cased file extension - the part of
       * the filename after the last period.
       * <p>
       * For example, getFileExtension("myPicture.is.cool.JPEG") would return
       * "jpeg".
       * 
       * @param f
       *          The file
       * @return The file extension in lower case, or null if none exists.
       */
    public static String getFileExtension(File f) {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');
        if (i > 0 && i < s.length() - 1) {
            ext = s.substring(i + 1).toLowerCase();
        }
        return ext;
    }
}

Related

  1. getFileExtension(File f)
  2. getFileExtension(File f)
  3. getFileExtension(File f)
  4. getFileExtension(File f)
  5. getFileExtension(File f)
  6. getFileExtension(File f)
  7. getFileExtension(File f)
  8. getFileExtension(File file)
  9. getFileExtension(File file)