Change file or directory permission using java
The setReadOnly, setWritable,setReadable and setExecutable methods of the file class is used for changing the permissions on a file.
import java.io.File;
/**
* File class examples.
* Performs different permission operations on a file or directory.
*/
public class FileExample {
public static void main(String[] args){
// Create file object representing the source file/directory
File file = new File("d:\\temp\\test.txt");
// Given below are the different file permissions
// operations that can be performed on java.
// Make the file or directory as executable
file.setExecutable(true);
// Make the file or directory as read only
file.setReadOnly();
// Make the file as writable.
file.setWritable(true);
// Give read permission to the file or directory
file.setReadable(true);
}
}
