Java File Extension Name Get extractExtension(final String fileName)

Here you can find the source of extractExtension(final String fileName)

Description

Extract the file extension from a string.

License

Open Source License

Parameter

Parameter Description
name A zipEntry file name.

Return

The zipEntry extension, or null if not found.

Declaration

private static String extractExtension(final String fileName) 

Method Source Code

//package com.java2s;
/*/*  w  w w  .  j av  a 2 s  .c o  m*/
 *    Geotoolkit - An Open Source Java GIS Toolkit
 *    http://www.geotoolkit.org
 *
 *    (C) 2008 - 2009, Geomatys
 *
 *    This library 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 2.1 of the License, or (at your option) any later version.
 *
 *    This library 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.
 */

public class Main {
    /**
     * Extract the file extension from a string. 
     * If the there is no extension, return null.
     * 
     * @param name A zipEntry file name.
     * @return The zipEntry extension, or null if not found.
     */
    private static String extractExtension(final String fileName) {
        final int dotIndex = fileName.lastIndexOf('.');
        if (dotIndex != -1) {
            return fileName.substring(dotIndex + 1);
        } else {
            return null;
        }
    }
}

Related

  1. extractExtension(String fileName)
  2. extractExtension(String name)
  3. extractExtension(String s)
  4. extractExtension(String strFilename)