Java File Name Get getFileName(String fileName)

Here you can find the source of getFileName(String fileName)

Description

get File Name

License

Open Source License

Declaration

public static final String getFileName(String fileName) 

Method Source Code


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

public class Main {

    public static final String getFileName(String fileName) {
        if (isEmpty(fileName)) {
            return null;
        }//from   www . j a  v a2s.co  m
        return fileName.substring(0, fileName.lastIndexOf("."));
    }

    public static String getFileName(File file) {
        if (file == null) {
            return null;
        }
        return getFileName(file.getName());
    }

    public static final boolean isEmpty(String input) {
        if (input == null || "".equals(input))
            return true;
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmpty(Object object) {
        return toString(object).isEmpty();
    }

    public static <T> boolean isEmpty(T[] array) {
        return (array == null) || (array.length == 0);
    }

    public static String toString(Object object) {
        return (object == null) ? "" : object.toString();
    }
}

Related

  1. getFilename(Locale locale, String fileName, String fileType)
  2. getFileName(String absolutePath)
  3. getFileName(String completePath)
  4. getFileName(String dir, String name)
  5. getFileName(String f)
  6. getFileName(String filePath)
  7. getFileName(String filePath)
  8. getFileName(String filepath)
  9. getFileName(String filePath)