Java File Name Get getFilenameWithoutAnyExtension(File file)

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

Description

Gets the name of the supplied file without any extension.

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static String getFilenameWithoutAnyExtension(File file) 

Method Source Code

//package com.java2s;
/*// w  w w  . j  a va2 s .c om
 * FrontlineSMS <http://www.frontlinesms.com>
 * Copyright 2007, 2008 kiwanja
 * 
 * This file is part of FrontlineSMS.
 * 
 * FrontlineSMS is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * FrontlineSMS 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 Lesser
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with FrontlineSMS. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

public class Main {
    /**
     * Gets the name of the supplied file without any extension.
     * @param file
     */
    public static String getFilenameWithoutAnyExtension(File file) {
        return getFilenameWithoutAnyExtension(file.getName());
    }

    public static String getFilenameWithoutAnyExtension(String filename) {
        int dotIndex = filename.indexOf('.');
        if (dotIndex > -1)
            filename = filename.substring(0, dotIndex);
        return filename;
    }
}

Related

  1. getFileNameStartingWith(String directory, String prefix)
  2. getFilenameSuffix(final File file)
  3. getFileNameUtil(String dataPath)
  4. getFileNameWithAddedExtension(File parent, File f, String ext)
  5. getFileNameWithNewExtension(File parent, File file, String ext)
  6. getFileNameWithoutExt(File file)
  7. getFileNameWithoutExt(File filePath)
  8. getFileNameWithoutExt(String file)
  9. GetFileNameWithoutExt(String file_path)