Java File Name Get getFilenameOnly(File file)

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

Description

Get the file name with the dot and extension stripped off.

License

Open Source License

Parameter

Parameter Description
file The input file to get the name of.

Return

The file name.

Declaration

public static String getFilenameOnly(File file) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/* w w w.  jav a  2s . c om*/
     * Get the file name with the dot and extension stripped off.
     * @param file The input file to get the name of.
     * @return The file name.
     */
    public static String getFilenameOnly(File file) {
        String filename = file.getName();
        if (filename.contains(".")) {
            return filename.substring(0, filename.lastIndexOf("."));
        }
        return null;
    }
}

Related

  1. getFileNameList(String dir)
  2. getFileNameList(String path)
  3. getFileNameNoSuffix(String fullName)
  4. getFileNameNoSuffix(String path)
  5. getFileNameOfPath(final String filePath)
  6. getFileNameOnly(String fileName)
  7. getFileNameOnlyFromFileObject(File fileToProcess)
  8. getFileNamePart(final File file)
  9. getFilenameParts(File file)