Java Path File Name nio getName(String path)

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

Description

Get the name and extension of a file

License

Open Source License

Parameter

Parameter Description
path The path to the file.

Return

The file name and extension.

Declaration

public static String getName(String path) 

Method Source Code


//package com.java2s;
// The MIT License(MIT)

import java.net.URI;

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

public class Main {
    /**//from  ww w.  j  ava2 s.  c om
     * <p>
     * Get the name and extension of a file.
     * </p>
     *
     * @param uri The {@link URI} of the file.
     * @return The file name and extension.
     */
    public static String getName(URI uri) {
        return getName(Paths.get(uri));
    }

    /**
     * <p>
     * Get the name and extension of a file
     * </p>
     *
     * @param path The path to the file.
     * @return The file name and extension.
     */
    public static String getName(String path) {
        return getName(Paths.get(path));
    }

    private static String getName(Path path) {
        Path fileName = path.getFileName();

        if (fileName != null) {
            return fileName.toString();
        }

        return null;
    }
}

Related

  1. getManifestProperty(Path pathToJar, String propertyName)
  2. getName(Path file)
  3. getName(Path path)
  4. getName(Path path)
  5. getName(Path path)
  6. getNamePart(Path file)
  7. getNameWithoutSuffix(Path path)
  8. getNormalizedFileName(Path file)
  9. getPackageURI(String pkgName, String pkgPath, String currentPkgName)