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.io.File; public class Main { public static String getFileExtension(File file) { return getFileExtension(file.getPath()); }//ww w .j a v a 2 s . c o m public static String getFileExtension(String path) { int dot = indexOfDot(path); if (dot < 0) { return null; } else { return path.substring(dot + 1); } } private static int indexOfDot(String path) { int baseNameStart = path.lastIndexOf(File.separatorChar); if (baseNameStart < 0) { baseNameStart = 0; } else { ++baseNameStart; } int dot = -1; int pos = path.length(); while ((pos = path.lastIndexOf('.', pos - 1)) > baseNameStart) { dot = pos; } return dot; } }