Output:
import java.io.File;
import java.io.IOException;
public class ExampleFilePermission
{
public static void main( String[] args )
{
File file = new File("test.txt");
if(file.exists()){
System.out.println("Execution allowed: " + file.canExecute());
System.out.println("Write allowed: " + file.canWrite());
System.out.println("Read Allowed: " + file.canRead());
}
file.setExecutable(false);
file.setReadable(false);
file.setWritable(false);
System.out.println("Execution allowed: " + file.canExecute());
System.out.println("Write allowed: " + file.canWrite());
System.out.println("Read Allowed: " + file.canRead());
}
}
Execution allowed: true
Write allowed: true
Read allowed: true
Execution allowed: false
Write allowed: false
Read allowed: false
Please disable your ad blocker and refresh the window to use this website.