/** * Load the file names of all files in the given directory. * * @param dirName Directory (folder) name. * @param suffix File suffix of interest. * @return The names of files found. */ private String[] findFiles(String dirName, String suffix) { File dir = new File(dirName); if (dir.isDirectory()) { String[] allFiles = dir.list(); if (suffix == null) { return allFiles; } else { List<String> selected = new ArrayList<String>(); for (String filename : allFiles) { if (filename.endsWith(suffix)) { selected.add(filename); } } return selected.toArray(new String[selected.size()]); } } else { System.out.println("Error: " + dirName + " must be a directory"); return null; } }