CodesJava

Easy learning with example program codes

set file permissions java program

Example:

package com.codesjava;
 
import java.io.File;
 
public class FilePermissions {
  public static void main(String args[]){
      File file = new File("D:/Test files/file 3.txt");
      System.out.println("Current file permissions:");
      System.out.println("Can Execute? "+file.canExecute());
      System.out.println("Can Read? "+file.canRead());
      System.out.println("Can Write? "+file.canWrite());
      file.setExecutable(false);
      file.setReadable(false);
      file.setWritable(false);
      System.out.println("Now file permissions:");
      System.out.println("Can Execute? "+file.canExecute());
      System.out.println("Can Read? "+file.canRead());
      System.out.println("Can Write? "+file.canWrite());
  }
}

Download this example.

Please follow and like us:
error
Posted in IO   








Copyright © 2019 CodesJava DMCA.com Protection Status