Java Utililty Methods File Find

List of utility methods to do File Find

Description

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

Method

StringfindExe(String exeName, String... path)
Find the executable with the given name by checking the directories in the given path in order.
for (String dir : path) {
    File f = new File(dir + "/" + exeName);
    if (f.exists()) { 
        return f.getPath();
return null;
FilefindExecutable(File baseLocation)
find Executable
File plugins = new File(baseLocation, "features");
FilenameFilter filter = new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.startsWith("org.eclipse.equinox.executable");
};
String[] files = plugins.list(filter);
if (files != null && files.length > 0)
...
FilefindExecutable(String executableName)
find Executable
String systemPath = System.getenv("PATH");
String[] pathDirs = systemPath.split(File.pathSeparator);
File fullyQualifiedExecutable = null;
for (String pathDir : pathDirs) {
    File file = new File(pathDir, executableName);
    if (file.isFile() && file.canExecute()) {
        fullyQualifiedExecutable = file;
        break;
...
FilefindExecutableInDirectory(String executable, File directory)
Tries to find the given executable (specified by its name) in the given directory.
if (directory == null || !directory.isDirectory()) {
    return null;
for (String extension : EXECUTABLE_EXTENSIONS) {
    File file = new File(directory, executable + extension);
    if (file.isFile() && file.canExecute()) {
        return file;
return null;
FilefindExecutableInPath(String exec)
find Executable In Path
List<String> candidates = new ArrayList<String>();
candidates.add(exec);
candidates.add(exec + ".exe");
candidates.add(exec + ".bat");
candidates.add(exec + ".cmd");
candidates.add(exec + ".sh");
candidates.add(exec + ".bash");
String systemPath = System.getenv("PATH");
...
FilefindExecutableInSystemPath(String executable)
Tries to find the given executable (specified by its name) in the system's path.
String systemPath = System.getenv("PATH");
if (systemPath == null) {
    return null;
String[] pathDirs = systemPath.split(File.pathSeparator);
for (String pathDir : pathDirs) {
    File dir = new File(pathDir);
    if (dir.isDirectory()) {
...
StringfindExecutableLocation(String executableName)
find Executable Location
return findExecutableLocation(executableName, new String[] {});
StringfindExecutableOnPath(String executable)
Checks the system path for the provided executable.
if (executable.contains(File.separator))
    return executable;
String systemPath = System.getenv("PATH");
if (systemPath == null)
    systemPath = System.getenv("path");
if (systemPath == null || File.pathSeparator == null)
    return executable;
String[] pathDirs = systemPath.split(File.pathSeparator);
...
FilefindExecutableOnPath(String executableName)
Find an executable based on given name from the PATH.
String systemPath = System.getenv("PATH");
String[] pathDirs = systemPath.split(File.pathSeparator);
return findExecutableOnPath(executableName, pathDirs);
FilefindExecutableOnPath(String executableName)
Tries to find the given executable on the path
File fullyQualifiedExecutable = null;
fullyQualifiedExecutable = new File(expandPath(executableName));
if (fullyQualifiedExecutable.isFile()) {
    return fullyQualifiedExecutable;
String systemPath = System.getenv("PATH");
String[] pathDirs = systemPath.split(File.pathSeparator);
for (String pathDir : pathDirs) {
...