Java File Extension Name Extract getFileExtension(File file)

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

Description

get File Extension

License

Open Source License

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 {

    public static String getFileExtension(File file) {

        String filename = file.getName().trim().toLowerCase();
        if (filename.length() == 0)
            return "";
        if (filename.charAt(filename.length() - 1) == '.')
            filename = filename.substring(0, filename.length() - 1);

        int lastPointIndex = filename.lastIndexOf('.');
        if (lastPointIndex < 0)
            return "";
        else//from w  w w . j a v a2s . c  o m
            return filename.substring(lastPointIndex + 1, filename.length());
    }
}

Related

  1. extractFileExtension(String filename)
  2. extractFileExtension(String filePath)
  3. extractFileExtension(String path)
  4. extractFileExtensionFromPath(String path)
  5. getFileExtension(File f)
  6. getFileExtension(File file)
  7. getFileExtension(File file)
  8. getFileExtension(File file)
  9. getFileExtension(File file)