Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { public static String extension(String filename) { if (filename == null || filename.length() == 0) { return ""; } // Ensure the last dot is after the last file separator int lastSep = filename.lastIndexOf(File.separatorChar); int lastDot; if (lastSep < 0) { lastDot = filename.lastIndexOf('.'); } else { lastDot = filename.substring(lastSep + 1).lastIndexOf('.'); if (lastDot >= 0) { lastDot += lastSep + 1; } } if (lastDot >= 0 && lastDot > lastSep) { return filename.substring(lastDot + 1).toLowerCase(); } return ""; } }