JAvaファイルの権限の設定方法

1171 ワード

import java.io.File;
import java.io.IOException;
/×
×                ,  createNewFile()        644.
×/ 
public class FilePermission 
{
    public static void main( String[] args )
    {	
    	try {
    		File file = new File("/home/test3.txt");
  	      if (file.createNewFile()){
	          System.out.println("File is created!");
 	        //Runtime.getRuntime().exec("chmod 777 /home/test3.txt"); 
                   file.setExecutable(true);//       
	          file.setReadable(true);//      
	          file.setWritable(true);//      
	          System.out.println("is execute allow : " + file.canExecute());
		      System.out.println("is read allow : " + file.canRead());
		      System.out.println("is write allow : " + file.canWrite());
	      }else{
	          System.out.println("File already exists.");
	      }
 
    	} catch (IOException e) {
	      e.printStackTrace();

    }
    }
}