Link to home
Start Free TrialLog in
Avatar of finaris
finarisFlag for Germany

asked on

Java File properties canRead, canWrite, canExecute

Hi Experts,

for checking file attributes read/write/execute, I currently use
java.io.File.canRead()
java.io.File.canWrite()
java.io.File.canExecute()

In some cases, these functions do NOT return expected results on Windows:

1) canWrite() is TRUE for files on a CD/DVD drive
2) canWrite() is TRUE for files that i cannot access due to missing privileges
3) canWrite() is FALSE for files that do not exist
...

Is a better API/library available to solve all this, or will I have to implement native OS-specific code for this issue?

I already tried the Apache VFS library, which does not return expected results either.
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I support rrz's proposal.

Remark:
>> 3) canWrite() is FALSE for files that do not exist
Seems correct to me. (You cannot write to an unexisting file)

Documentation about canWrite():
true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.
Avatar of finaris

ASKER

works as expected, thanks