Java Path File Name nio getFileNameWithoutExt(final Path file)

Here you can find the source of getFileNameWithoutExt(final Path file)

Description

Returns the file name of the specified file without its extension.

License

Apache License

Parameter

Parameter Description
file file whose name without extension to be returned

Return

the file name of the specified file without its extension

Declaration

public static String getFileNameWithoutExt(final Path file) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.file.Path;

public class Main {
    /**/*  w w  w . ja v  a  2s.co m*/
     * Returns the file name of the specified file without its extension.
     * 
     * @param file file whose name without extension to be returned
     * @return the file name of the specified file without its extension
     */
    public static String getFileNameWithoutExt(final Path file) {
        final String fileName = file.getFileName().toString();

        final int dotIdx = fileName.lastIndexOf('.');
        return dotIdx > 0 ? fileName.substring(0, dotIdx) : fileName;
    }
}

Related

  1. getFileNameFromPath(String str)
  2. getFilenameOrLastPath(String path)
  3. getFileNames(List fileNames, Path dir)
  4. getFileNames(List fileNames, Path dir, String ext, boolean recursive)
  5. getFileNames(List fileNames, Path dir, String sFilter)
  6. getFilePath(String dirName)
  7. getFilePathName(Path filePath)
  8. getFilePathsInFolder(String sensorName)
  9. getFilesFromDirectory(Path directory, List filenames)