Java File Naked Name Get getFileWithoutEnding(String absolutePath)

Here you can find the source of getFileWithoutEnding(String absolutePath)

Description

get File Without Ending

License

Open Source License

Declaration

public static String getFileWithoutEnding(String absolutePath) 

Method Source Code


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

import java.io.File;

public class Main {
    public static String getFileWithoutEnding(File f) {
        return getFileWithoutEnding(f.getAbsolutePath());
    }/*  w w  w .j av  a2s.  c o m*/

    public static String getFileWithoutEnding(String absolutePath) {
        return separateFileNameFromEnding(getFile(absolutePath));
    }

    public static String separateFileNameFromEnding(File f) {
        String name = f.getName();
        if (name.contains(".")) {
            return name.substring(0, name.lastIndexOf('.'));
        }
        return name;
    }

    public static String separateFileNameFromEnding(String file) {
        if (file.contains(".")) {
            return file.substring(0, file.lastIndexOf('.'));
        }
        return file;
    }

    public static String getFile(File f) {
        return getFile(f.getAbsolutePath());
    }

    public static String getFile(String absolutePath) {
        if (absolutePath.endsWith(File.separator)) {
            return "";
        }
        return absolutePath.substring(absolutePath.lastIndexOf(File.separator) + 1, absolutePath.length());
    }
}

Related

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