Here you can find the source of getName(String path)
Get the name and extension of a file
Parameter | Description |
---|---|
path | The path to the file. |
public static String getName(String path)
//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; } }