Here you can find the source of getFileExtension(File file)
public static String getFileExtension(File file)
//package com.java2s; /*//from w ww . j a v a2 s .c om * Static String formatting and query routines. * Copyright (C) 2001,2002 Stephen Ostermiller <utils@Ostermiller.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * See COPYING.TXT for details. */ import java.io.File; public class Main { public static String getFileExtension(File file) { return getFileExtension(file.getPath()); } public static String getFileExtension(String pathName) { // getting the extension of a filename, (plain or including dirname) // This code is much faster than any regex technique. // filename without the extension String choppedFilename; // extension without the dot String ext; // where the last dot is. There may be more than one. int dotPlace = pathName.lastIndexOf('.'); if (dotPlace >= 0) { // possibly empty choppedFilename = pathName.substring(0, dotPlace); // possibly empty ext = pathName.substring(dotPlace + 1); } else { // was no extension choppedFilename = pathName; ext = ""; } return ext; } }