• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File.setReadOnly()

 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
There is method 'boolean setReadOnly()' in java.io.File class. With this i can make the file read-only. But there is no way to remove the read-only attribute. There are no methods like unsetReadOnly() or setReadWrite(). Any ideas how to do this?
 
feng chou
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
public class test{
public static void main(String[] args)
throws IOException{
int c;
BufferedInputStream i=
new BufferedInputStream(
new FileInputStream("readOnlyFile");
BufferedOutputStream o=
new BufferedOutputStream(
new FileOutputStream(
"canWriteFile");
while((c=i.read())!=-1)
o.write(c);
in.close();
out.close();
}
}//you can try these codes.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
This code may work. But it may not solve my problem. I've asked whether there are any programmatic ways to unset a readOnly flag which is set using the setReadOnly() method of java.io.File class..
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic