Can I do this on Java? I'm using windows...
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.");
}
public boolean setWritable(boolean writable)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With