Java File Name Get getFileNameWithoutExtension(File file)

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

Description

get File Name Without Extension

License

Open Source License

Declaration

public static String getFileNameWithoutExtension(File file) 

Method Source Code

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

import java.io.File;

public class Main {
    public static String getFileNameWithoutExtension(File file) {
        String fileName = null;/*from ww  w . j  a v a2s. c om*/

        if (file == null) {
            throw new IllegalArgumentException("file cannot be null");
        }

        int fileExtensionIndex = file.getName().lastIndexOf(".");

        if (fileExtensionIndex <= 0) {
            return file.getName();
        }

        fileName = file.getName().substring(0, fileExtensionIndex);

        return fileName;
    }
}

Related

  1. getFileNameWithoutExt(String filePath)
  2. getFileNameWithoutExt(String originPath)
  3. getFilenameWithoutExtension(File f)
  4. getFileNameWithoutExtension(File file)
  5. getFileNameWithoutExtension(File file)
  6. getFileNameWithoutExtension(File file)
  7. getFileNameWithoutExtension(File file)
  8. getFileNameWithoutExtension(File file)
  9. getFileNameWithoutExtension(File file)