Java File Name Get getFileNameWithoutExtension(String fullFilename)

Here you can find the source of getFileNameWithoutExtension(String fullFilename)

Description

Returns file name without extension.

License

Open Source License

Parameter

Parameter Description
fullFilename file name with extension.

Return

file name without extension.

Declaration

public static String getFileNameWithoutExtension(String fullFilename) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

import java.io.File;

public class Main {
    /**//from   w w w .j av  a2  s. com
     * Returns file name without extension.
     * We do not use the method from Guava library to reduce Checkstyle's dependencies
     * on external libraries.
     * @param fullFilename file name with extension.
     * @return file name without extension.
     */
    public static String getFileNameWithoutExtension(String fullFilename) {
        final String fileName = new File(fullFilename).getName();
        final int dotIndex = fileName.lastIndexOf('.');
        final String fileNameWithoutExtension;
        if (dotIndex == -1) {
            fileNameWithoutExtension = fileName;
        } else {
            fileNameWithoutExtension = fileName.substring(0, dotIndex);
        }
        return fileNameWithoutExtension;
    }
}

Related

  1. getFileNameWithoutExtension(final String filePath)
  2. getFileNameWithoutExtension(String fileName)
  3. getFileNameWithoutExtension(String filePath)
  4. getFileNameWithoutExtension(String filePath)
  5. getFileNameWithoutExtension(String filePath)
  6. getFileNameWithoutExtensionFromPath(String s)
  7. getFilenameWithoutExtention(File file)
  8. getFileNameWithoutFilePath(File f)
  9. getFilenameWithoutPath(String path)