Can I do this on Java? I'm using windows...
+2
A:
http://java.sun.com/j2se/1.6.0/docs/api/java/io/File.html#setReadOnly%28%29
File file = new File("foo.bar");
if(file.setReadOnly()) {
System.out.println("Successful");
}
else {
System.out.println("All aboard the fail train.");
}
Before Java6, you could not undo this. To get around this, they put in File.setWritable(boolean)
which can be used as so
File file = new File("foo.bar");
if(file.setWritable(false)) {
System.out.println("Successful");
}
else {
System.out.println("All aboard the fail train.");
}
if(file.setWritable(true)) {
System.out.println("Re-enabled writing");
}
else {
System.out.println("Failed to re-enable writing on file.");
}
glowcoder
2010-05-20 19:31:07
A:
MUG4N
2010-05-20 19:31:29
+1
A:
final File f = new File(...);
f.setWritable(true);
Will change premissions to writable (not read-only).
Note: this may not work all the times, as the underlying FileSystem may deny the request. But it works on most files on your hard drives.
Pindatjuh
2010-05-20 19:32:47
Don't you mean `f.setWritable(false);` to make it read only?
glowcoder
2010-05-20 19:35:33
@Glowcoder: Maybe I've misinterpret the "unmark file is read-only". I thought it means to make it *not* "read-only", which is writable, which is `true`, right?
Pindatjuh
2010-05-20 19:37:11
@Pind oh wow, you might just be right there. Perhaps it is I who misinterpreted the question.
glowcoder
2010-05-20 19:42:30
Yes, that's how I eventually interpreted the question too. It's phrased terribly, and the question itself is split between the title and the body. I'd downvote it but I don't want to spend the rep.
Stephen P
2010-05-20 20:02:45