Java File Name Get GetFileNameWithoutExt(String file_path)

Here you can find the source of GetFileNameWithoutExt(String file_path)

Description

Returns the name of the file without the extension

License

Open Source License

Parameter

Parameter Description
file_path a parameter

Declaration

public static String GetFileNameWithoutExt(String file_path) 

Method Source Code

//package com.java2s;
/*Copyright 2008 by Vladimir Polony, Stupy 24, Banska Bystrica, Slovakia
    /*from  w w w. j a  v  a2s .  c  om*/
This file is part of OpenRep FREE homeopathic software.
    
OpenRep FREE 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.
    
OpenRep FREE 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 OpenRep FREE.  If not, see <http://www.gnu.org/licenses/>.*/

public class Main {
    /** standard extension of any file == '.' */
    public static final String FILE_EXTENSION_SEPARATOR = ".";

    /** Returns the name of the file without the extension
     * 
     * @param file_path
     * @return
     */
    public static String GetFileNameWithoutExt(String file_path) {
        int pos = file_path.lastIndexOf(FILE_EXTENSION_SEPARATOR);
        int pos2 = file_path.lastIndexOf(GetDirectorySeparator());
        if (pos2 < pos)
            return file_path.substring(0, pos);
        else
            return file_path;
    }

    /** Returns the Directory Separator used in the current operating system Windows = \ Linux = /
     * 
     * @return
     */
    public static char GetDirectorySeparator() {
        return java.io.File.separatorChar;
    }
}

Related

  1. getFileNameWithNewExtension(File parent, File file, String ext)
  2. getFilenameWithoutAnyExtension(File file)
  3. getFileNameWithoutExt(File file)
  4. getFileNameWithoutExt(File filePath)
  5. getFileNameWithoutExt(String file)
  6. getFileNameWithoutExt(String fileName)
  7. getFileNameWithoutExt(String filePath)
  8. getFileNameWithoutExt(String originPath)
  9. getFilenameWithoutExtension(File f)