Check the file permissions
file.canExecute() // Checks if file is executable or not
file.canWrite() // Checks if file is writable or not
file.canRead() // Checks if file is readable or not
Set the file permission
file.setExecutable(boolean); // Sets execute permission and return true
file.setReadable(boolean); // Sets read permission and return true
file.setWritable(boolean); // Sets write permission and return true
Check if a file is hidden
File file = new File("c:/hidden-file.txt");
if(file.isHidden())
System.out.println("This file is hidden");
else
System.out.println("This file is not hidden");
Making file Read only and Read / Write
File file = new File("c:/MyFile.txt");
// Set the file as read only
file.setReadOnly();
if(file.canWrite())
System.out.println("This file is writable");
else
System.out.println("This file is read only");
// Set the file as writable
file.setWritable(true);
if(file.canWrite())
System.out.println("This file is writable");
else
System.out.println("This file is read only");
No comments:
Post a Comment
Note: only a member of this blog may post a comment.