Java-io-file-canexecute
提供:Dev Guides
Java.io.File.canExecute()メソッド
説明
- java.io.File.canExecute()*メソッドは、抽象名でファイルを実行できる場合にtrueを返します。
宣言
以下は* java.io.File.canExecute()*メソッドの宣言です-
public boolean canExecute()
パラメーター
NA
戻り値
このメソッドはブール値を返します。 パス名が存在し、アプリケーションによるファイルの実行が許可されている場合はtrue。
例外
*SecurityException* -ファイルの実行が許可されていない場合。
例
次の例は、java.io.File.canExecute()メソッドの使用法を示しています。
package com.finddevguides;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
String[] strs = {"test.txt", "/test.txt"};
try {
//for each string in string array
for(String s:strs ) {
//create new file
f = new File(s);
//true if the file is executable
boolean bool = f.canExecute();
//find the absolute path
String a = f.getAbsolutePath();
//prints absolute path
System.out.print(a);
//prints
System.out.println(" is executable: "+ bool);
}
} catch(Exception e) {
//if any I/O error occurs
e.printStackTrace();
}
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
D:\EclipseAndroid\IO\BufferedInputStream\test.txt is executable: true
D:\test.txt is executable: false