Java File Name Get getFileNameNoSuffix(String path)

Here you can find the source of getFileNameNoSuffix(String path)

Description

Get just the file name without a suffix from a path

License

Open Source License

Parameter

Parameter Description
path a parameter

Declaration

public static String getFileNameNoSuffix(String path) 

Method Source Code

//package com.java2s;
/**//  w w w  . j av a  2s .  c  om
 * nz.govt.natlib.ndha.common.Common - Software License
 *
 * Copyright 2007/2008 National Library of New Zealand.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *
 * or the file "LICENSE.txt" included with the software.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * FileUtils.java
 * $Rev$
 * PlayerM
 * 26/11/2007
 *
 */

import java.io.File;

public class Main {
    /**
     * Get just the file name without a suffix from a path
     *
     * @param path
     * @return
     */
    public static String getFileNameNoSuffix(String path) {
        return getFileNameNoSuffix(new File(path));
    }

    /**
     * Get just the file name without a suffix from a file
     *
     * @param file
     * @return
     */
    public static String getFileNameNoSuffix(File file) {
        String fileName = file.getName();
        int dotPos = fileName.lastIndexOf(".");
        if (dotPos >= 0) {
            fileName = fileName.substring(0, dotPos);
        }
        return fileName;
    }
}

Related

  1. getFileNameInJCCTrayHome(String fileName)
  2. getFileNameList(File[] files)
  3. getFileNameList(String dir)
  4. getFileNameList(String path)
  5. getFileNameNoSuffix(String fullName)
  6. getFileNameOfPath(final String filePath)
  7. getFilenameOnly(File file)
  8. getFileNameOnly(String fileName)
  9. getFileNameOnlyFromFileObject(File fileToProcess)