Thursday 12 February 2015

How To Change File Permission Using Java

In last tutorial we learn How To Check File Permissions In Java ,Now We learn how to change file permission using java code. now firstly we create a file and check its permission


Now we use this java code
 public class ChangeFilePermission {
  
      public static void main(String[] args) {
          String path="D:\\file\\read.txt";
        File file=new File(path);
        if (file.exists()) {
            System.out.println("read="+file.canRead());
            System.out.println("write="+file.canWrite());
            System.out.println("Execute="+file.canExecute());
            file.setReadOnly();
        }      
    }
    
}
Now we again check file permission.Definitely it will as ...

 


No comments:

Post a Comment