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.
finarisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzCommented:
Which version of Java are you using?  
Version 1.7 gave us new API for files. I haven't used them. You could test  these static methods.  They are in the  java.nio.file  package.
Files.isExecutable(path)
Files.isReadable(path)
Files.isWritable(path)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSr. Software engineerCommented:
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.
0
finarisAuthor Commented:
works as expected, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.