Java Path File Name nio getFilename(final Path path)

Here you can find the source of getFilename(final Path path)

Description

Needed to get rid of findbugs "dodgy code warnings" in regards to getting the filename of a path as a string

License

Open Source License

Parameter

Parameter Description
path the path that you which to get the filename as a string

Return

the filename or an empty string

Declaration

public static String getFilename(final Path path) 

Method Source Code

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

import java.nio.file.Path;

public class Main {
    /**//from w ww .j ava  2 s  . co m
     * Needed to get rid of findbugs "dodgy code warnings" in regards to getting the filename of a path as a string
     * 
     * @param path the path that you which to get the filename as a string
     * @return the filename or an empty string
     */
    public static String getFilename(final Path path) {
        String filename = "";
        if (path != null) {
            final Path filenamePath = path.getFileName();
            if (filenamePath != null) {
                filename = filenamePath.toString();
            }
        }

        return filename;
    }
}

Related

  1. getDefaultPathName(final String address, final long lspId)
  2. getDirectoryNames(Path baseDirectory)
  3. getFileContent(String fileNameOrPath)
  4. getFileInFolder(Path p, String filename)
  5. getFilename (final String filepath)
  6. getFilename(final Path path)
  7. getFileName(Path path)
  8. getFileName(Path path)
  9. getFileName(String fullPath, boolean withParentFolder)