Here you can find the source of getFileExtension(File file)
public static String getFileExtension(File file) throws FileNotFoundException
//package com.java2s; /*//from www. ja v a 2 s .co m * Copyright 2010 * IBB-CEB - Institute for Biotechnology and Bioengineering - Centre of Biological Engineering * CCTC - Computer Science and Technology Center * * University of Minho * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This code 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 Public License for more details. * * You should have received a copy of the GNU Public License * along with this code. If not, see http://www.gnu.org/licenses/ * * Created inside the SysBioPseg Research Group (http://sysbio.di.uminho.pt) */ import java.io.File; import java.io.FileNotFoundException; public class Main { public static String getFileExtension(File file) throws FileNotFoundException { if (file != null && file.exists()) { return getFileExtension(file.getAbsolutePath()); } else if (file == null) throw new NullPointerException("File is null"); else throw new FileNotFoundException("File [" + file.getAbsolutePath() + "] does not seem to exist."); } public static String getFileExtension(String fileName) { String extension = ""; int i = fileName.lastIndexOf('.'); int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\')); if (i > p) { extension = fileName.substring(i + 1); } return extension; } }