Java File Extension Name Extract extractFileExtension(String filename)

Here you can find the source of extractFileExtension(String filename)

Description

Extracts the file extension of the given file filename or empty string, if no file extension is available.

License

Open Source License

Parameter

Parameter Description
filename file name

Return

File extension or empty string

Declaration

public static String extractFileExtension(String filename) 

Method Source Code

//package com.java2s;
/* FeatureIDE - A Framework for Feature-Oriented Software Development
 * Copyright (C) 2005-2016  FeatureIDE team, University of Magdeburg, Germany
 *
 * This file is part of FeatureIDE./*from  ww w.  j ava2s  . co  m*/
 * 
 * FeatureIDE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * FeatureIDE 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with FeatureIDE.  If not, see <http://www.gnu.org/licenses/>.
 *
 * See http://www.fosd.de/featureide/ for further information.
 */

public class Main {
    /**
     * Extracts the file extension of the given file <b>filename</b> or empty string, if no file extension is available. 
     * The extension does not include the leading ".".
     * 
     * @param filename file name
     * @return File extension or empty string
     */
    public static String extractFileExtension(String filename) {
        final int position = filename.lastIndexOf('.');
        if (position > 0) {
            return filename.substring(position + 1);
        } else
            return "";
    }
}

Related

  1. extractFileExtension(String filename)
  2. extractFileExtension(String fileName)
  3. extractFileExtension(String filename)
  4. extractFileExtension(String fileName)
  5. extractFileExtension(String filename)
  6. extractFileExtension(String filePath)
  7. extractFileExtension(String path)
  8. extractFileExtensionFromPath(String path)
  9. getFileExtension(File f)