Java File Name Extract extractFilename(String path)

Here you can find the source of extractFilename(String path)

Description

Extract the filename from a (relative or absolute) path.

License

Open Source License

Parameter

Parameter Description
path The path to extract the filename from

Return

The filename portion of path

Declaration

public static String extractFilename(String path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2013 Research In Motion Limited
 *
 * 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
 *******************************************************************************/

public class Main {
    /**/*from   w w w  . j a v  a 2 s.c  om*/
     * Extract the filename from a (relative or absolute) path. Works with both
     * / and \ separators.
     * 
     * @param path
     *            The path to extract the filename from
     * @return The filename portion of path
     */
    public static String extractFilename(String path) {
        String result = path.substring(path.lastIndexOf('/') + 1);
        return result.substring(result.lastIndexOf('\\') + 1);
    }
}

Related

  1. extractFileName(String name)
  2. extractFilename(String path)
  3. extractFileName(String path)
  4. extractFileName(String path)
  5. extractFileName(String path)
  6. extractFileName(String url)
  7. extractFileNameFromBAMLocation(String location)
  8. extractFileNameFromContentDisposition(String contentDisposition)
  9. extractFileNameFromPath(final String filePath, char separatorChar)