How to read permissions in windows and NTFS?
Alan Bateman
Alan.Bateman at oracle.com
Fri Aug 27 04:56:20 PDT 2010
Sarah kho wrote:
> Hi,
> is there anyway to read file permissions in windows to see whether the
> current user has access to write on a file or not?
>
> thanks.
You need to use checkAccess(AccessMode.WRITE). Yes, we know this is a
bit clumsy at the moment.
As this is Windows then so I should just mention that the implementation
is based on a combination of the effective access (ACL), the DOS
read-only attribute, and whether the volume/drive is read-only.
One small comment is that many of the reasons for needing to check
access go away with this API and you might be better off without it.
For example, it is common to see code like:
if (f.canWrite()) {
/* open file for writing */
}
It is usually faster to simply just open the file for writing and you'll
get a reasonable exception if it fails (in this case, probably an
AccessDeniedException). The other benefit is security as many file
system based attacks exploit the window between the check and the usage.
-Alan.
More information about the nio-discuss
mailing list