How to do File.setReadOnly(boolean) in NIO.2

Alan Bateman Alan.Bateman at oracle.com
Mon May 30 00:59:41 PDT 2011


Christian Schlichtherle wrote:
>
> Hi,
>
>  
>
> I can find no equivalent to File.setReadOnly(boolean) using the NIO.2 
> API. I suppose I should be calling Files.setAttribute(*), but what is 
> the attribute parameter in a cross-platform way?
>
That's right, there isn't an exact equivalent as there isn't always a 
good mapping to the notion of "read only" to all file systems. This may 
be something to look at again in the future. For the default provider 
then you can still use toFile().setReadOnly(boolean) if needed but it 
will have the same issues as before - for example it doesn't work with 
directories on Windows for example.

-Alan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-discuss/attachments/20110530/a165bcb9/attachment.html 


More information about the nio-discuss mailing list