Java File Name Get getFileNameWithoutExtension(String filePath)

Here you can find the source of getFileNameWithoutExtension(String filePath)

Description

get File Name Without Extension

License

Apache License

Declaration

public static String getFileNameWithoutExtension(String filePath) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    public static String getFileNameWithoutExtension(String filePath) {
        if (filePath == null || filePath.trim().length() == 0) {
            return filePath;
        }/*from w  w w. ja v  a  2 s  .c  o  m*/

        int extenPosi = filePath.lastIndexOf(".");
        int filePosi = filePath.lastIndexOf(File.separator);
        if (filePosi == -1) {
            return (extenPosi == -1 ? filePath : filePath.substring(0, extenPosi));
        }
        if (extenPosi == -1) {
            return filePath.substring(filePosi + 1);
        }
        return (filePosi < extenPosi ? filePath.substring(filePosi + 1, extenPosi)
                : filePath.substring(filePosi + 1));
    }
}

Related

  1. getFilenameWithoutExtension(final File file)
  2. getFileNameWithoutExtension(final File file)
  3. getFilenameWithoutExtension(final String fileName)
  4. getFileNameWithoutExtension(final String filePath)
  5. getFileNameWithoutExtension(String fileName)
  6. getFileNameWithoutExtension(String filePath)
  7. getFileNameWithoutExtension(String filePath)
  8. getFileNameWithoutExtension(String fullFilename)
  9. getFileNameWithoutExtensionFromPath(String s)