Java File Extension Name Extract extractFileExtension(String filename)

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

Description

Extracts file extension (leaves last segment only)

License

Open Source License

Parameter

Parameter Description
filename absolute or relative filename with forward slashes as delimiters

Return

the result filename

Declaration

static public String extractFileExtension(String filename) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2015 ARM Ltd. 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://  w  w  w .  java  2 s.c o  m
* ARM Ltd and ARM Germany GmbH - Initial API and implementation
*******************************************************************************/

public class Main {
    /**
     * Extracts file extension (leaves last segment only)  
     * @param filename absolute or relative filename with forward slashes as delimiters
     * @return the result filename 
     */
    static public String extractFileExtension(String filename) {
        if (filename == null || filename.isEmpty())
            return filename;

        int pos = filename.lastIndexOf('.');
        if (pos >= 0) {
            return filename.substring(pos + 1);
        }
        return null;
    }
}

Related

  1. extractFileExt(String _sFilePathName)
  2. extractFileExt(String filePath)
  3. ExtractFileExtension(String file_name)
  4. extractFileExtension(String fileName)
  5. extractFileExtension(String filename)
  6. extractFileExtension(String fileName)
  7. extractFileExtension(String filename)