Java Path File Extention nio getFileNameWithoutExtension(Path path)

Here you can find the source of getFileNameWithoutExtension(Path path)

Description

Gets the file name of the given path without the extension.

License

Open Source License

Parameter

Parameter Description
path the path.

Exception

Parameter Description
NullPointerException if the path has zero elements or is null.

Return

the base file name (without directory path and leading ".").

Declaration

public static String getFileNameWithoutExtension(Path path) 

Method Source Code

//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);
        }
    }
}

Related

  1. getFileExtension(Path path)
  2. getFileExtension(Path path)
  3. getFileExtension(Path path)
  4. getFileNameNoExtensionFromPath(String modulePath)
  5. getFilenameWithoutExtension(Path file)
  6. getFileNameWithoutExtension(Path path)
  7. getFileNameWithoutExtension(String filePath)
  8. getFilesList(Path directory, Set extensions)
  9. getFullNameWithoutExtension(Path f)