Here you can find the source of getFileExtension(File path)
public static String getFileExtension(File path)
//package com.java2s; /*//w ww .ja v a2 s . c om * ==================================================================== * Copyright (c) 2004-2012 TMate Software Ltd. All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://svnkit.com/license.html * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * ==================================================================== */ import java.io.File; public class Main { public static String getFileExtension(File path) { if (path == null) return null; return getFileNameExtension(path.getName()); } public static String getFileNameExtension(String name) { if (name == null) return null; int dotInd = name.lastIndexOf('.'); if (dotInd != -1 && dotInd != 0 && dotInd != name.length() - 1) { return name.substring(dotInd + 1); } return null; } }