Java File Name Get getFileNameWithoutExt(String originPath)

Here you can find the source of getFileNameWithoutExt(String originPath)

Description

Get the file name without extension, given a complete path.

License

Open Source License

Parameter

Parameter Description
originPath The complete path.

Declaration

public static String getFileNameWithoutExt(String originPath) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {
    /**// www. j a v a2 s  .  c o  m
     * Get the file name without extension, given a complete path.
     * @param originPath The complete path.
     * @return
     */
    public static String getFileNameWithoutExt(String originPath) {
        String name = "";
        try {
            String fileName = getFileName(originPath);
            name = fileName.substring(0, fileName.lastIndexOf('.'));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return name;
    }

    /**
     * Get the file name, given a complete path.
     * @param originPath The complete path.
     * @return
     */
    public static String getFileName(String originPath) {
        String file = "";
        try {
            file = originPath.substring(originPath.lastIndexOf(File.separatorChar) + 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return file;
    }
}

Related

  1. getFileNameWithoutExt(File filePath)
  2. getFileNameWithoutExt(String file)
  3. GetFileNameWithoutExt(String file_path)
  4. getFileNameWithoutExt(String fileName)
  5. getFileNameWithoutExt(String filePath)
  6. getFilenameWithoutExtension(File f)
  7. getFileNameWithoutExtension(File file)
  8. getFileNameWithoutExtension(File file)
  9. getFileNameWithoutExtension(File file)