Here you can find the source of extractExtension(String strFilename)
public static String extractExtension(String strFilename)
//package com.java2s; /*/* ww w . ja v a 2s . com*/ * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is "EINRC-7 / GDEM project". * * The Initial Developer of the Original Code is TietoEnator. * The Original Code code was developed for the European * Environment Agency (EEA) under the IDA/EINRC framework contract. * * Copyright (C) 2000-2004 by European Environment Agency. All * Rights Reserved. * * Original Code: Kaido Laine (TietoEnator) */ public class Main { /** * Extracts file extension from filename. */ public static String extractExtension(String strFilename) { return extractExtension(strFilename, "xml"); } public static String extractExtension(String strFilename, String defaultExt) { String strExtension = ""; int index = strFilename.lastIndexOf('.'); // if the "." is before the 5 chars at the end of file name, then it's // not probably a file name if (index > strFilename.length() - 5) { strExtension = strFilename.substring(index + 1, strFilename.length()); strExtension = strExtension.toLowerCase(); return strExtension; } return defaultExt; } }