Here you can find the source of getFileNameWithoutExtension(Path path)
Parameter | Description |
---|---|
path | the path. |
Parameter | Description |
---|---|
NullPointerException | if the path has zero elements or is null. |
public static String getFileNameWithoutExtension(Path path)
//package com.java2s; //License from project: Open Source License import java.nio.file.Path; public class Main { /**//from w ww . j av a 2 s .co m * Gets the file name of the given path without the extension. The extension begins at the last occurrence of ".". * Returns the base name if there is no extension or the file begins with a dot ("."). * * @param path the path. * @return the base file name (without directory path and leading "."). * @throws NullPointerException if the path has zero elements or is null. * @see Path#getFileName() */ public static String getFileNameWithoutExtension(Path path) { String name = path.getFileName().toString(); int index = name.lastIndexOf('.'); if (index <= 0) { return name; } else { return name.substring(0, index); } } }