Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static String getFileExtension(File file) { String name = file.getName(); int lastIndexOf = name.lastIndexOf("."); if (lastIndexOf == -1) { return ""; // empty extension } return name.substring(lastIndexOf); } }