例子
以下示例显示java.io.File.canExecute()方法的用法。
package com.jc2182;
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