Java File Extension Name Get getFileExtension(final String fullName)

Here you can find the source of getFileExtension(final String fullName)

Description

Returns the file extension for the given file name, or the empty string if the file has no extension.

License

Open Source License

Parameter

Parameter Description
fullName a parameter

Return

file extension or empty string if the file has no extension

Declaration

public static String getFileExtension(final String fullName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2014 compeople AG and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* ww  w.ja v a  2  s .c  om*/
 *    compeople AG - initial API and implementation
 *******************************************************************************/

import java.io.File;
import org.eclipse.core.runtime.Assert;

public class Main {
    /**
     * Returns the file extension for the given file name, or the empty string if the file has no extension. The result does not include the '.'.
     * 
     * @param fullName
     * @return file extension or empty string if the file has no extension
     */
    public static String getFileExtension(final String fullName) {

        Assert.isNotNull(fullName, "fullName must be given!"); //$NON-NLS-1$

        final String fileName = new File(fullName).getName();
        final int dotIndex = fileName.lastIndexOf('.');
        return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1); //$NON-NLS-1$

    }
}

Related

  1. getFileExtension(File file, boolean withDot)
  2. getFileExtension(final File aFile)
  3. getFileExtension(final File file)
  4. getFileExtension(final File file)
  5. getFileExtension(final String file)
  6. getFileExtension(String file)
  7. getFileExtension(String fileName)
  8. getFileExtension(String fileName)
  9. getFileExtension(String filename)