Here you can find the source of getFileExtension(File file)
public static String getFileExtension(File file)
//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; } }