Java Path File Name nio getFilenameOrLastPath(String path)

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

Description

Parses a full path, returning the filename.

License

Open Source License

Parameter

Parameter Description
path The path to be parsed

Return

The filename of last part of the specified full path

Declaration

public static String getFilenameOrLastPath(String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**//from  w  w w .  jav a 2s .com
     * Parses a full path, returning the filename. If full path is a directory,
     * returns its last part
     * @param path The path to be parsed
     * @return The filename of last part of the specified full path
     */
    public static String getFilenameOrLastPath(String path) {
        Path p = Paths.get(path);

        return p.getFileName().toString();
    }
}

Related

  1. getFileName(String fullPath, boolean withParentFolder)
  2. getFileName(String path)
  3. getFileName(String relativePath)
  4. getFileNameFromPath(String filePath)
  5. getFileNameFromPath(String str)
  6. getFileNames(List fileNames, Path dir)
  7. getFileNames(List fileNames, Path dir, String ext, boolean recursive)
  8. getFileNames(List fileNames, Path dir, String sFilter)
  9. getFileNameWithoutExt(final Path file)