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.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.File;

public class Main {
    private final static Pattern FileNamePattern = Pattern.compile("(?:-([0-9]*))?(?:\\.([^.]*))?$");

    public static String getFileExtension(File file) {
        String path = file.getPath();
        Matcher matcher = FileNamePattern.matcher(path);
        if (matcher.find()) {
            return matcher.group(2);
        }/*from   w  w  w. j a va  2  s. c  o m*/
        return null;
    }
}

Related

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