Java File Name Extract extractFileName(String path)

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

Description

Pass in /sub/dir/path.html returns path.html

License

Open Source License

Parameter

Parameter Description
inPath a parameter

Declaration

public static String extractFileName(String path) 

Method Source Code

//package com.java2s;
/*//  w  ww .  ja  v  a 2s  . c  o m
Copyright (c) 2003 eInnovation Inc. All rights reserved
    
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 {
    /**
     * Pass in /sub/dir/path.html returns path.html
     * 
     * @param inPath
     * @return
     */
    public static String extractFileName(String path) {

        if (path == null) {
            return null;
        }
        String newpath = path.replace('\\', '/');
        int start = newpath.lastIndexOf("/");
        if (start == -1) {
            start = 0;
        } else {
            start = start + 1;
        }
        String pageName = newpath.substring(start, newpath.length());

        return pageName;
    }
}

Related

  1. extractFileName(String fn)
  2. extractFileName(String fullPath)
  3. extractFileName(String name)
  4. extractFilename(String path)
  5. extractFilename(String path)
  6. extractFileName(String path)
  7. extractFileName(String path)
  8. extractFileName(String url)
  9. extractFileNameFromBAMLocation(String location)