Example:
package com.w3spoint;
import java.io.File;
public class FilePermissions {
public static void main(String args[]){
File file = new File("D:/Test files/file 3.txt");
System.out.println("Current file permissions:");
System.out.println("Can Execute? "+file.canExecute());
System.out.println("Can Read? "+file.canRead());
System.out.println("Can Write? "+file.canWrite());
file.setExecutable(false);
file.setReadable(false);
file.setWritable(false);
System.out.println("Now file permissions:");
System.out.println("Can Execute? "+file.canExecute());
System.out.println("Can Read? "+file.canRead());
System.out.println("Can Write? "+file.canWrite());
}
} |
package com.w3spoint; import java.io.File; public class FilePermissions {
public static void main(String args[]){
File file = new File("D:/Test files/file 3.txt");
System.out.println("Current file permissions:");
System.out.println("Can Execute? "+file.canExecute());
System.out.println("Can Read? "+file.canRead());
System.out.println("Can Write? "+file.canWrite());
file.setExecutable(false);
file.setReadable(false);
file.setWritable(false);
System.out.println("Now file permissions:");
System.out.println("Can Execute? "+file.canExecute());
System.out.println("Can Read? "+file.canRead());
System.out.println("Can Write? "+file.canWrite());
}
}
Download this example.