Java Program To Set File Permission
Chapter:
File
Last Updated:
13-02-2017 07:05:04 UTC
Program:
/* ............... START ............... */
public class JavaSetFilePermission {
public static void main(String[] args) {
File file=new File("c:\JavaScan.txt");
file.setReadable(false);
// Sets the write permissions for file JavaScan.txt to false
file.setWritable(false);
System.out.println("Allow file read "+file.canRead());
System.out.println("Allow file write "+file.canWrite());
}
}
/* ............... END ............... */
Output
Allow file read false
Allow file write false
Notes:
-
To set the read permissions to a file from java code use setReadable method of File class to true or false.
- To set the write permissions to a file from java code use setWritable method of File class to true or false.
Tags
Set File Permission, Java, File