Java File Naked Name Get extractFileWithoutExtension(String filename)

Here you can find the source of extractFileWithoutExtension(String filename)

Description

extract File Without Extension

License

Open Source License

Declaration

public static String extractFileWithoutExtension(String filename) 

Method Source Code

//package com.java2s;

public class Main {
    public static String extractFileWithoutExtension(String filename) {
        try {//from  ww w . j a  v  a2 s . co m
            int cutlen = extractFileExtension(filename).length();
            if (cutlen == 0)
                return filename;
            return filename.substring(0, filename.length() - cutlen - 1);
        } catch (Exception e) {
            return filename;
        }
    }

    public static String extractFileExtension(String filename) {
        int lastslash = filename.lastIndexOf("/");
        if (lastslash != -1)
            filename = filename.substring(lastslash + 1);
        lastslash = filename.lastIndexOf("\\");
        if (lastslash != -1)
            filename = filename.substring(lastslash + 1);
        int lastdot = filename.lastIndexOf(".");
        if (lastdot != -1)
            return filename.substring(lastdot + 1);
        else
            return "";
    }
}

Related

  1. extractFileNameWithoutExt(String filePath)
  2. extractFileNameWithSuffix(String filePathName)
  3. extractFileWithoutPath(String input)
  4. fileNameWithoutExtension(String filename)
  5. filenameWithoutExtension(String filename)
  6. getFilenameNoExt(File f)