Java File Name Get getFilenameWithoutExtension(File f)

Here you can find the source of getFilenameWithoutExtension(File f)

Description

get Filename Without Extension

License

Open Source License

Return

the filename of f without extension

Declaration

public static String getFilenameWithoutExtension(File f) 

Method Source Code


//package com.java2s;
/*//from   ww  w. j a v a  2s. co m
GanttProject is an opensource project management tool.
Copyright (C) 2005-2011 GanttProject team
    
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import java.io.File;

public class Main {
    private static final char FILE_EXTENSION_SEPARATOR = '.';

    /** @return the filename of f without extension */
    public static String getFilenameWithoutExtension(File f) {
        String filename = f.getName();
        int i = filename.lastIndexOf(FILE_EXTENSION_SEPARATOR);
        return i >= 0 ? filename.substring(0, i) : filename;
    }
}

Related

  1. getFileNameWithoutExt(String file)
  2. GetFileNameWithoutExt(String file_path)
  3. getFileNameWithoutExt(String fileName)
  4. getFileNameWithoutExt(String filePath)
  5. getFileNameWithoutExt(String originPath)
  6. getFileNameWithoutExtension(File file)
  7. getFileNameWithoutExtension(File file)
  8. getFileNameWithoutExtension(File file)
  9. getFileNameWithoutExtension(File file)