Java File Extension Name Get getFileExtension(File f)

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

Description

get File Extension

License

Open Source License

Parameter

Parameter Description
f the file

Return

the extension of f

Declaration

public static String getFileExtension(File f) 

Method Source Code

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

import java.io.File;

public class Main {
    /**/*w  w  w.j  a v a  2 s .  c  om*/
     * @param f
     *            the file
     * @return the extension of f
     */
    public static String getFileExtension(File f) {
        if (f.isFile()) {
            String name = f.getName();
            int pos = name.lastIndexOf(".");
            if (pos != -1) {
                return name.substring(pos + 1, name.length());
            }
        }

        return "";
    }
}

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 file)
  8. getFileExtension(File file)
  9. getFileExtension(File file)