Java File Name Get getFilenameWithoutPath(String path)

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

Description

Takes a filename with path and returns just the filename.

License

Open Source License

Parameter

Parameter Description
path Absolute path

Return

Filename without the path prefix

Declaration

public static String getFilenameWithoutPath(String path) 

Method Source Code


//package com.java2s;
/*//  www. j av  a2 s. com
Copyright (c) 2008-2010 Daniel Marbach & Thomas Schaffter
    
We release this software open source under an MIT license (see below). If this
software was useful for your scientific work, please cite our paper(s) listed
on http://gnw.sourceforge.net.
    
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
    
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import java.io.File;

public class Main {
    /***
    * Takes a filename with path and returns just the filename.
    * @param path Absolute path
    * @return Filename without the path prefix
    */
    public static String getFilenameWithoutPath(String path) {
        File f = new File(path);
        return f.getName();
    }
}

Related

  1. getFileNameWithoutExtension(String filePath)
  2. getFileNameWithoutExtension(String fullFilename)
  3. getFileNameWithoutExtensionFromPath(String s)
  4. getFilenameWithoutExtention(File file)
  5. getFileNameWithoutFilePath(File f)
  6. getFileNameWithPath(String path, String fileNameWithoutFullPath)