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 = file.getName().trim();
        if (filename.length() == 0)
            return "";
        if (filename.charAt(filename.length() - 1) == '.')
            filename = filename.substring(0, filename.length() - 1);

        int lastPointIndex = filename.lastIndexOf('.');
        if (lastPointIndex < 0)
            return filename;
        else if (lastPointIndex == 0)
            return "";
        else//  w  w w.j  a  v  a  2 s  . co m
            return filename.substring(0, lastPointIndex);
    }
}

Related

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