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(String path)
return file name without extension from path
String name = new File(path).getName();
int ind = name.lastIndexOf('.');
if (ind > 0)
    return name.substring(0, ind);
else
    return name;
StringgetFileName(String path)
get File Name
return getFileName(path, true);
StringgetFileName(String path)
Dado un nombre de archivo completo, devuelve el nombre sin la extension
String fileName = null;
String separator = File.separator;
int pos = path.lastIndexOf(separator);
int pos2 = path.lastIndexOf(".");
if (pos2 > -1)
    fileName = path.substring(pos + 1, pos2);
else
    fileName = path.substring(pos + 1);
...
StringgetFilename(String path)
get Filename
return getFilename(path, File.separator);
StringgetFileName(String s)
Return file name with no path but with extension
String ret = s;
int sl = ret.lastIndexOf(File.separator);
if (sl < 0)
    sl = ret.lastIndexOf('/');
if (sl > 0)
    ret = ret.substring(sl + 1);
return ret;
StringgetFileName(String s)
Get the name of a file without extension from a string Added by JG 2017
if (s != "") {
    File f = new File(s);
    return f.getName();
return s;
StringgetFileName(String s)
get File Name
int index = s.lastIndexOf("/");
String name = null;
if (index > -1) {
    name = s.substring(index + 1);
} else {
    index = s.lastIndexOf(File.separator);
    if (index > 0) {
        name = s.substring(index + 1);
...
StringgetFileName(String template, String className, String packageName)
get File Name
String packagePath = packageName.replace(".", File.separator) + File.separator;
if (template.contains("Entity.java.vm")) {
    return packagePath + "entity" + File.separator + className + "Entity.java";
return null;
StringgetFileName(String url, String basePath)
get File Name
String[] url1 = url.split("cxedocs");
String after = url1[1];
String before = basePath;
if (before == null) {
    before = new File(".").getAbsolutePath();
String fileName = before + after;
return fileName;
...
StringgetFileNameAndExt(String s)
Get the file name with it's extension from a string Added by JG 2017
if (s != "") {
    String tmp = getCanonicalPath(s);
    int pos1 = tmp.lastIndexOf(File.separator);
    int pos2 = tmp.length();
    if (pos1 > 0 && pos2 > pos1 + 1)
        return tmp.substring(pos1 + 1, pos2);
return s;
...