How To Check File Permissions In Java

In this program we learn how to know about file permission mode using java code.

Now we create a file in read only mode .

public class FilePermission
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());
}

}

}


Output:
read=true
write=false
Execute=true

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 30 = 35