Java File Extension Name Get getFileExtension(File file)

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

Description

Gets the file extension from a file

License

Open Source License

Parameter

Parameter Description
file The file to get the file extension

Return

The file extension

Declaration


static String getFileExtension(File file) 

Method Source Code


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

import java.io.File;

public class Main {
    /**//from   ww  w. j  a  va  2 s .  com
     * Gets the file extension from a file
     * 
     * @param file
     *          The file to get the file extension
     * @return The file extension
     */
    // visible for testing
    static String getFileExtension(File file) {
        if (file == null) {
            return null;
        }
        if (!file.getName().contains(".")) {
            return null;
        }
        return file.getName().substring(file.getName().lastIndexOf('.') + 1);
    }
}

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, boolean includeDot)