Tutorialspoint examples

Learn java tutorial with examples for beginners online

set file permissions java program


Example:

package com.tutorialspointexamples;
 
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.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status