Java Utililty Methods File Attribute

List of utility methods to do File Attribute

  1. HOME
  2. Java
  3. F
  4. File Attribute

Description

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

Method

boolean checkIfExecutableIsInPATH(final String executableName)
Check if an executable is in the PATH.
if (executableName == null) {
 throw new NullPointerException("executableName argument cannot be null");
final String pathEnv = System.getenv("PATH");
if (pathEnv == null) {
 return false;
final FilenameFilter filter = new FilenameFilter() {
...
boolean doesExecutableExist(String executablePath)
does Executable Exist
if (new File(executablePath).exists()) {
 return true;
String systempath = System.getenv("PATH");
String[] paths = systempath.split(File.pathSeparator);
for (String path : paths) {
 if (new File(path, executablePath).exists()) {
 return true;
...
void ensureExecutable(final File file)
ensure Executable
if (!file.canExecute() && !file.setExecutable(true)) {
 throw new IllegalStateException(String.format("Failed to set %s executable", file.getAbsolutePath()));
void ensureExecutable(IPath path)
ensure Executable
if (pathExists(path)) {
 File file = path.toFile();
 if (!file.canExecute()) {
 if (!file.setExecutable(true)) {
 file.setExecutable(true, true);
boolean ensureFileIsExecutable(String filename)
Ensure that given file, if it exists, is executable
File file = new File(filename);
if (file.exists()) {
 if (file.canExecute()) {
 return true;
 return file.setExecutable(true);
return false;
...
void fileExecute(String path)
file Execute
try {
 Process child = Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", path });
} catch (IOException e) {
 e.printStackTrace();
String findInPath(String executable, String path, String pathSeparator)
Works kind of like the "which" program; the method won't try to apply PATHEXT to executable when searching the PATH.
final String[] parts = path.split(pathSeparator);
for (String part : parts) {
 final File potentialExecutable = new File(part, executable);
 if (potentialExecutable.exists()) {
 executable = potentialExecutable.getAbsolutePath();
 break;
return executable;
File findJavaCompilerExecutableInDir(File dir)
find Java Compiler Executable In Dir
if (dir == null || !dir.exists() || !dir.isDirectory()) {
 return null;
for (String candidateJavaCompilerFileName : CANDIDATE_JAVAC_FILES) {
 File javaCompilerFile = new File(dir, candidateJavaCompilerFileName);
 if (javaCompilerFile.exists()) {
 return javaCompilerFile;
return null;
File findJavaExecutable(File vmInstallLocation)
Starting in the specified VM install location, attempt to find the 'java' executable file.
for (int i = 0; i < CANDIDATE_JAVA_EXECUTABLES.length; i++) {
 for (int j = 0; j < CANDIDATE_JAVA_LOCATIONS.length; j++) {
 File javaFile = new File(vmInstallLocation,
 CANDIDATE_JAVA_LOCATIONS[j] + CANDIDATE_JAVA_EXECUTABLES[i]);
 if (javaFile.isFile()) {
 return javaFile;
return null;
String findUnixExecutable(String unixCommandLineExecutables)
find Unix Executable
String[] default_exec = unixCommandLineExecutables.split(",");
String[] appendPath = null;
if (isMacOS()) {
 appendPath = new String[1];
 appendPath[0] = "PATH=$PATH:" + System.getProperty("user.home") + "/bin:/opt/local/bin";
try {
 for (String exec : default_exec) {
...


AltStyle によって変換されたページ (->オリジナル) /