Java File Naked Name Get getFileNameNoExtension(File file)

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

Description

Get Filename minus it's extension if present

License

Open Source License

Parameter

Parameter Description
file File to get filename from

Return

String filename minus its extension

Declaration

public static String getFileNameNoExtension(File file) 

Method Source Code

//package com.java2s;
/*//w w w. j  a  v  a  2s  .  c  o m
 * Copyright (c) 2012 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.io.File;

public class Main {
    /**
     * Get Filename minus it's extension if present
     * 
     * @param file
     *            File to get filename from
     * @return String filename minus its extension
     */
    public static String getFileNameNoExtension(File file) {
        return getFileNameNoExtension(file.getName());
    }

    /**
     * Get Filename minus it's extension if present
     * 
     * @param fileName path to get filename of
     * @return String filename minus its extension
     */
    public static String getFileNameNoExtension(String fileName) {
        int posExt = fileName.lastIndexOf(".");
        // No File Extension
        return posExt == -1 ? fileName : fileName.substring(0, posExt);

    }
}

Related

  1. fileNameWithoutExtension(String filename)
  2. filenameWithoutExtension(String filename)
  3. getFilenameNoExt(File f)
  4. getFileNameNoExt(File file)
  5. getFileNameNoExt(String path)
  6. getFileWithoutEnding(String absolutePath)
  7. getFileWithoutExtension(File f)
  8. getFileWithoutExtension(File file)