Checking permissions : File Read Write « Security « Java






Checking permissions

 
import java.io.File;

public class Permissions {
  public static void main(String[] args) {
    if (args.length != 1) {
      System.err.println("usage: java Permissions filespec");
      return;
    }

    File file = new File(args[0]);

    System.out.println("Checking permissions for " + args[0]);
    System.out.println("  Execute = " + file.canExecute());
    System.out.println("  Read = " + file.canRead());
    System.out.println("  Write = " + file.canWrite());
  }
}

 








Related examples in the same category

1.Writable, read only file
2.Authenticate and login context
3.Authorized File Writer