Java File Extension Name Get getFileExtension(File file)

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

Description

Get the file extension of given file.

License

Open Source License

Parameter

Parameter Description
file A given file.

Return

String the file extension if any, otherwise null.

Declaration

public static String getFileExtension(File file) 

Method Source Code

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

import java.io.File;

public class Main {
    /**/* ww  w.j a  v  a 2  s  .  c o  m*/
     * Get the file extension of given file.
     *
     * @param file A given file.
     * @return String the file extension if any, otherwise null.
     */
    public static String getFileExtension(File file) {
        String fileName = file.getName();
        int position = fileName.lastIndexOf('.');
        if (position == -1)
            return null;
        return fileName.substring(position + 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, boolean includeDot)
  7. getFileExtension(File file, boolean withDot)
  8. getFileExtension(final File aFile)
  9. getFileExtension(final File file)