Java Utililty Methods File Name Get

List of utility methods to do File Name Get

Description

The list of methods to do File Name Get are organized into topic(s).

Method

StringgetFileName(File file)
get File Name
String filename;
String[] parts = file.toString().split(Pattern.quote("\\"));
filename = parts[parts.length - 1]; 
String[] segs = filename.split(Pattern.quote("."));
filename = segs[segs.length - 2];
return filename;
StringgetFileName(File file)
get File Name
assert (file != null);
if (!file.exists()) {
    return null;
String filepath = file.getName();
int i = filepath.lastIndexOf(File.separator);
return (i >= 0) ? filepath.substring(i + 1) : filepath;
StringgetFilename(File file)
On Windows machines the path contains "\\", however, when converted to a String, this becomes "\".
return file.getAbsolutePath().replaceAll("\\\\", "\\\\\\\\");
StringgetFilename(File file)
get Filename
return getFilename(file.getName());
StringgetFilename(File file)
return filename without the path.
String ext = getExtension(file);
String base = getBase(file);
return setExtension(ext, base);
StringgetFileName(File file)
get File Name
if (file.isDirectory()) {
    return file.getName();
String name = file.getName();
return name.substring(0, name.indexOf("."));
StringgetFileName(File file)
get File Name
if (file.isDirectory()) {
    return file.getName();
} else {
    String fileType = getFileType(file);
    if ("unknown".equals(fileType)) {
        return file.getName();
    } else {
        String fileName = file.getName();
...
StringgetFileName(File file)
get File Name
return file.getName();
StringgetFilename(File file, boolean withExtension)
get Filename
String[] piece = _splitPathName(file);
if (withExtension) {
    return piece[FILENAME] + piece[EXTENSION];
return piece[FILENAME];
StringgetFileName(File path)
Returns the file name (without extension) given a absolute path.
String fName;
int idx;
fName = path.getName();
if (fName.length() == 0)
    return null;
idx = fName.lastIndexOf('.');
if (idx < 0)
    return fName;
...