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;
import java.util.Locale;

public class Main {
    public static String getFileNameWithoutExtension(File file) {

        if (file == null)
            return null;

        String fileExt = getFileExtension(file);
        String fileName = file.getName();
        return fileName.substring(0, fileName.length() - fileExt.length() - 1);

    }//from  w  w  w. j a  v  a2s .c  o  m

    public static String getFileExtension(File file) {

        if (file == null)
            return null;

        String fileName = file.getName();
        String fileExt = null;
        int i = fileName.lastIndexOf(".");
        if (i > 0 && i < fileName.length() - 1) {
            fileExt = fileName.substring(i + 1).toLowerCase(Locale.ENGLISH);
        }

        return fileExt;

    }
}

Related

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