Java File Name Get getFileNameWithoutExtension(File file)

Here you can find the source of getFileNameWithoutExtension(File file)

Description

Get the short name portion of a filename not including the extension.

License

Open Source License

Parameter

Parameter Description
file The File in question

Return

The name part of a file name excluding the extension

Declaration

public static String getFileNameWithoutExtension(File file) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    /**//from   ww  w  .j  a  v a2 s. c om
     * Get the short name portion of a filename not including the extension.
     * @param file The File in question
     * @return The name part of a file name excluding the extension
     */
    public static String getFileNameWithoutExtension(File file) {
        String fileName = file.getName();
        int i = fileName.lastIndexOf('.');
        if (i > 0 && i < fileName.length() - 1) {
            return fileName.substring(0, i);
        } else {
            return fileName;
        }
    }
}

Related

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