Java tutorial
//package com.java2s; import java.io.File; public class Main { /** * Gets the extension of a file. * * @param f the file * @return the extension of the file. */ public static String getExtension(File f) { return getExtension(f.getName()); } /** * Gets the extension of a file. * * @param fileName the file name * @return the extension of the file. */ public static String getExtension(String fileName) { String ext = null; int i = fileName.lastIndexOf('.'); if (i > 0 && i < fileName.length() - 1) { ext = fileName.substring(i + 1).toLowerCase(); } return ext; } }