Java tutorial
//package com.java2s; import java.io.File; public class Main { /** * If filename is "abc.def", return "def". * @param fin File to get extension * @return String extension without '.' */ public static String getExtension(File fin) { //if a file named "abc.def" , then return "def" . String fname = fin.getName(); //To find the last '' int where = 0; for (int i = fname.length() - 1; i >= 0; --i) { if (fname.charAt(i) == '.') { where = i; break; } } if (where == 0 || where >= fname.length()) { return ""; } else { return fname.substring(where + 1); } } }