In this program we learn how to know about file permission mode using java code.
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
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
No comments:
Post a Comment