JDK-4167472 : File.setReadOnly() should take a boolean argument indicating writability
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.2.0,1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_95
  • CPU: generic,x86
  • Submitted: 1998-08-19
  • Updated: 2005-11-03
  • Resolved: 2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6 b51Fixed
Name: diC59631			Date: 08/19/98

Why not :

  java.io.File.setReadOnly(boolean mode)

to be able to set it true/false as for a lock-file
mechanism ?
(Review ID: 37210)

Name: rmT116609			Date: 11/20/2000

java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Server VM (build 2.0fcs-E, mixed mode)

in the java.io.class there is a method to make a file read only.
however this can't be undone. we need a methos like setReadOnly(boolean).
calling this method with a false argument should make the file modifiable.
we also need a method isReadOnly() to test this condition.
(Review ID: 112499)

Name: rmT116609			Date: 02/08/2001

java version "1.3.0"

java.io.File class can set read-only attribute on a file
(with setReadOnly() method) but it cannot clear it. If a
Java program encounters a read-only file which it needs
to write or delete, it can only do that using JNI. It's
also unable to undo the effect of previous setReadOnly()
call if it makes one. IMO there should be a method like
setReadOnly(boolean) so that setReadOnly(false) would make
the file writeable or throw an IOException is such operation
is not allowed
(Review ID: 116607)

EVALUATION The java.io.File class has a setReadOnly operation but no corresponding way to make a file writable because it is not clear how to specify the latter operation. In particular, on multi-user systems you have to answer the question of "writable by whom?" Even to ask this question requires dealing with user identities, which is not something that the Java platform is yet capable of doing. That will likely change in a future feature release, at which time we'll revisit this issue. In the absence of a way to make an existing file writable, you can always delete the read-only file and rewrite a new, writable version. This is what many source-code-control systems do anyway. -- mr@eng 1998/10/30 Adding following methods in Mustang setWritable(boolean writable, boolean ownerOnly); setReadable(boolean readable, boolean ownerOnly) setExecutable(boolean executable, boolean ownerOnly); setExecutable(boolean executable); setReadable(boolean readable); setWritable(boolean writable); canExecute();