Here you can find the source of getSimpleName(String path)
Get the name of a file.
Parameter | Description |
---|---|
path | The path to the file. |
public static String getSimpleName(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 { /**/* w w w . j a v a 2s .co m*/ * <p> * Get the name of a file. * </p> * * @param uri The {@link URI} of the file. * @return The file name. */ public static String getSimpleName(URI uri) { return getSimpleName(Paths.get(uri)); } /** * <p> * Get the name of a file. * </p> * * @param path The path to the file. * @return The file name. */ public static String getSimpleName(String path) { return getSimpleName(Paths.get(path)); } private static String getSimpleName(Path path) { String fileName = getName(path); if (fileName != null) { return fileName.substring(0, fileName.lastIndexOf('.')); } return null; } /** * <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; } }