• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Java File properties canRead, canWrite, canExecute

Hi Experts,

for checking file attributes read/write/execute, I currently use

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.
1 Solution
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.
zzynxSoftware engineerCommented:
I support rrz's proposal.

>> 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.
finarisAuthor Commented:
works as expected, thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now