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) { 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()); } }