Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Write to files that are readonly  RSS feed

 
seb petterson
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How do you write over a file that is readonly? Or, how do you unset the readonly property.

Seb
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use RandomAccessFile
 
Robert Hill
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where in RandomAccessFile is there a mechanism to defeat what is usually an OS controlled function?

If a file is read only, there is usually a good reason for it. If you want write access to a normally read only file, you should have very good reason to do so.
 
Ådne Brunborg
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why indeed... except that there may be legitimate reasons, such as your application should be able to write to the file, but no other (e.g. a version control application).

Anyways, a quick Google search on "java access permissions" returns this artricle on Java 6 SE "Mustang" as the first hit, and I quote:

The current access permissions, as applied to the individual attempting to access the object, may cause some of File�s methods to fail. For this reason, Mustang introduces six new File methods that let you modify the pathname�s access permissions:
[...]
public boolean setWritable(boolean writable, boolean ownerOnly)
[...]


So, I think, as per now (Java 5), you can't.
 
Robert Hill
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't mean to imply there is no good reason ever. Just that if the file is not specific to your app and is read-only, you better have a pressing and legitimate need, else you can find yourself in a security "quagmire".

Java 6 is out now, and it seemed to be a quiet release. Not as much fanfare as 1.5 was.
[ January 15, 2007: Message edited by: Robert Hill ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!