HOME      BLOG       FORUMS      CONTACT       ABOUT

Change file or directory permission only to owner using java

Change file or directory permission only to owner using java

The setReadOnly, setWritable,setReadable and setExecutable methods of the file class is used for changing the permissions on a file only to owner of the file or directory.

import java.io.File;
 * File class examples. 
 * The class sets read only, writable, executable and readable permissions
 * for a file or directory. This permissions will be applied to the owner of
 * the file or directory only. Not everyone will get the permissions.
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.
		// Give executable permission to a file or directory
		file.setExecutable(true, true);
		// Set read only property to a file or a directory
		// Give write permission to the file
		file.setWritable(true, true);
		// Make the file or directory as readable
		file.setReadable(true, true);

Tags: , , , ,

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply