Here you can find the source of fileName(final Path thePath)
public static String fileName(final Path thePath)
//package com.java2s; /*/*from w w w .j a v a2 s . c o m*/ * Copyright (c) 2013 christianr. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0.html * * Contributors: * christianr - initial API and implementation */ import java.nio.file.FileSystems; import java.nio.file.Path; public class Main { /** * Gets the name of the given file without an extension. * @param theFile path to get the name * @return name of the given file without an extension. */ public static String fileName(final String theFile) { int myIndex = theFile.lastIndexOf('.'); final int mySeperator = theFile.lastIndexOf(FileSystems .getDefault().getSeparator()); if (myIndex < mySeperator) myIndex = -1; if (myIndex < 0) return theFile.substring(Math.max(0, mySeperator)); return theFile.substring(Math.max(0, mySeperator), myIndex); } public static String fileName(final Path thePath) { return fileName(thePath.getFileName().toString()); } }