Here you can find the source of getFilenameWithoutExtension(Path file)
Parameter | Description |
---|---|
file | Path to the file |
Parameter | Description |
---|---|
Exception | File not have extension |
public static String getFilenameWithoutExtension(Path file)
//package com.java2s; //License from project: Open Source License import java.nio.file.Path; public class Main { /**//from ww w. j a v a 2s . co m * Gets the filename without the extension * * @param file Path to the file * @return Filename without extension * @throws Exception File not have extension */ public static String getFilenameWithoutExtension(Path file) { return getFilenameWithoutExtension(file.getFileName().toString()); } /** * Gets the filename without the extension * * @param fullFilename Full filename * @return Filename without extension * @throws Exception File not have extension */ public static String getFilenameWithoutExtension(String fullFilename) { String[] tokens = fullFilename.split("\\."); // if the file does not have an extension if (tokens.length <= 1) { return fullFilename; } String filename = new String(); for (int i = 0; i < tokens.length - 1; i++) { filename += tokens[i]; } return filename; } }