Writable, read only file : File Read Write « Security « Java






Writable, read only file

 
import java.io.File;

public class ROW {
  public static void main(String[] args) {
    File filespec = new File("c:\text.txt");

    if (filespec.setWritable(false))
      System.out.println(filespec + " made read-only");
    else
      System.out.println("Permission denied");
    if (filespec.setWritable(true))
      System.out.println(filespec + " made writable");
    else
      System.out.println("Permission denied");

    System.out.println(filespec + " is currently "
        + (filespec.canWrite() ? "writable" : "read-only"));
  }
}

 








Related examples in the same category

1.Checking permissions
2.Authenticate and login context
3.Authorized File Writer