Java File Name Get getFileNameWithoutExt(String file)

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

Description

get File Name Without Ext

License

Open Source License

Declaration

public static String getFileNameWithoutExt(String file) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    public static String getFileNameWithoutExt(String file) {
        return file.substring(getSeparatorIndex(file), getDotIndex(file));
    }//w w  w .  ja  v a  2s  .co  m

    public static int getSeparatorIndex(String file) {
        int sepIndex = file.lastIndexOf(File.separator);

        if (sepIndex != -1)
            return sepIndex + 1;
        else
            return 0;
    }

    public static int getDotIndex(String file) {
        int dotIndex = file.lastIndexOf(".");

        if (dotIndex != -1)
            return dotIndex;
        else
            return file.length();
    }
}

Related

  1. getFileNameWithAddedExtension(File parent, File f, String ext)
  2. getFileNameWithNewExtension(File parent, File file, String ext)
  3. getFilenameWithoutAnyExtension(File file)
  4. getFileNameWithoutExt(File file)
  5. getFileNameWithoutExt(File filePath)
  6. GetFileNameWithoutExt(String file_path)
  7. getFileNameWithoutExt(String fileName)
  8. getFileNameWithoutExt(String filePath)
  9. getFileNameWithoutExt(String originPath)