Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /** * Gets the extension of a file name, like "png" or "jpg". * * @param uri * @return Extension excluding the dot("."); "" if there is no extension; * null if uri was null. */ public static String getExtension(String uri) { if (uri == null) { return null; } int dot = uri.lastIndexOf("."); if (dot >= 0) { return uri.substring(dot + 1); } else { // No extension. return ""; } } public static String getExtension(File file) { return getExtension(file.getName()); } }