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

StringgetFileNameInJCCTrayHome(String fileName)
get File Name In JCC Tray Home
return getFileName(JCCTRAY_HOME, fileName);
StringgetFileNameList(File[] files)
returns list of files as string, comma separated.
String list = "";
String listSep = ",";
for (int i = 0; i < files.length; i++) {
    if (files[i].isFile()) {
        list += (files[i].getName() + listSep);
return list.substring(0, list.length() - 1);
...
ListgetFileNameList(String dir)
Get file name list under a directory
List<String> fileNameList = new ArrayList<String>();
File _dir = new File(dir);
File[] files = _dir.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        if (files[i].isFile()) {
            String fileName = files[i].getName();
            fileNameList.add(fileName);
...
ArrayListgetFileNameList(String path)
get File Name List
File file = new File(path);
File[] tempList = file.listFiles();
ArrayList<Integer> tnames = new ArrayList<Integer>();
ArrayList<String> names = new ArrayList<String>();
for (int i = 0; i < tempList.length; i++) {
    if (tempList[i].isFile()) {
        tnames.add(Integer.valueOf(tempList[i].getName()));
Collections.sort(tnames);
for (int i = 0; i < tnames.size(); i++) {
    names.add(tnames.get(i) + "");
if (names.size() == 0)
    names.add("-1");
return names;
StringgetFileNameNoSuffix(String fullName)
get File Name No Suffix
String name = (new File(fullName)).getName();
if (name.lastIndexOf('.') > -1) {
    return name.substring(0, name.lastIndexOf('.'));
} else {
    return name;
StringgetFileNameNoSuffix(String path)
Get just the file name without a suffix from a path
return getFileNameNoSuffix(new File(path));
StringgetFileNameOfPath(final String filePath)
get File Name Of Path
final int lastIndexFileSep = filePath.lastIndexOf(File.separator);
return filePath.substring(lastIndexFileSep + 1);
StringgetFilenameOnly(File file)
Get the file name with the dot and extension stripped off.
String filename = file.getName();
if (filename.contains(".")) {
    return filename.substring(0, filename.lastIndexOf("."));
return null;
StringgetFileNameOnly(String fileName)
get File Name Only
int index = -1;
String auxString = fileName, returnedValue = null;
index = fileName.lastIndexOf(File.separator);
if (index == -1)
    index = fileName.lastIndexOf('/');
if (index != -1)
    auxString = fileName.substring(index + 1);
index = auxString.lastIndexOf('.');
...
StringgetFileNameOnlyFromFileObject(File fileToProcess)
get File Name Only From File Object
String result = fileToProcess.getAbsolutePath();
int index = result.lastIndexOf("/");
if (index == -1) {
    index = result.lastIndexOf("\\");
if (index != -1 && (index + 1) < result.length()) {
    result = result.substring(index + 1);
return result;