Java File Extension Name Get getFileExtension(File file)

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

Description

returns the file extension, or empty-string of the file has no extension.

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static String getFileExtension(File file) 

Method Source Code


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

import java.io.*;

public class Main {
    private static final String DOT = ".";

    /**/*from   w  w w .java 2 s. co  m*/
     * returns the file extension, or empty-string of the file has no extension.
     * @param file
     * @return
     */
    public static String getFileExtension(File file) {
        String filePath = file.getPath();
        int index = filePath.lastIndexOf(DOT);
        if (index >= 0)
            return filePath.substring(index + 1);
        else
            return "";
    }
}

Related

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