java - File.canExecute() says every file is executable? -
this question has answer here:
- in java file.canexecute() do? 3 answers
i using code test it;
public class canexecutetest { public static void main (string[] args) { file currentdir = new file(system.getproperty("user.dir")); traverse(currentdir); } public static void traverse(file dir) { string[] filesanddirs = dir.list(); (string fileordir : filesanddirs) { file f = new file(dir, fileordir); if (f.isdirectory()) { traverse(f); } else { system.out.print(f); if (f.canexecute()) { system.out.println(" can execute"); } else { system.out.println(" cannot execute"); } } } } }
this outputs every file executable file. doing wrong here, or java bug? on windows 7, netbeans 7.3.1 , java 7.
canexecute()
doesn't test executability, tests whether current program (i.e. yours) permitted execute it. example, if changed permissions of 1 of files 000 (no read, write, or execute user), canexecute()
return false jvm not have permission execute (or read) file.
if want check executable files, create method parses files suffix , returns true when finds .exe (or .app on os x).
Comments
Post a Comment