Java File Name Get getFileNameWithoutExtension(String fileName)

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

Description

Returns a file's name, without its extension.

License

Open Source License

Parameter

Parameter Description
fileName a String containing the file name

Return

a String containing the file name without extension

Declaration

public static String getFileNameWithoutExtension(String fileName) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    /**/*from   w  ww. ja  v a 2 s  .  c  om*/
     * Returns a file's name, without its extension.
     * 
     * @param fileName
     *            a String containing the file name
     * @return a String containing the file name without extension
     */
    public static String getFileNameWithoutExtension(String fileName) {
        int dotIndex = fileName.lastIndexOf('.');
        return fileName.substring(0, dotIndex);
    }

    /**
     * Returns a file's name, without its extension.
     * 
     * @param file
     *            the file
     * @return a String containing the file name without extension
     */
    public static String getFileNameWithoutExtension(File file) {
        return getFileNameWithoutExtension(file.getName());
    }
}

Related

  1. getFileNameWithoutExtension(File fx)
  2. getFilenameWithoutExtension(final File file)
  3. getFileNameWithoutExtension(final File file)
  4. getFilenameWithoutExtension(final String fileName)
  5. getFileNameWithoutExtension(final String filePath)
  6. getFileNameWithoutExtension(String filePath)
  7. getFileNameWithoutExtension(String filePath)
  8. getFileNameWithoutExtension(String filePath)
  9. getFileNameWithoutExtension(String fullFilename)