Answers for "checking file writable java"

0

checking file writable java

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FilesExample {
   public static void main(String args[]) {
      //Creating a Path object
      Path path = Paths.get("D:\\sample.txt");
      //Verifying if the file is readable
      boolean bool = Files.isReadable(path);
      if(bool) {
         System.out.println("readable");
      } else {
         System.out.println("not readable");
      }
      bool = Files.isWritable(path);
      if(bool) {
         System.out.println("writable");
      } else {
         System.out.println("not writable");
      }
      bool = Files.isExecutable(path);
      if(bool) {
         System.out.println("executable");
      } else {
         System.out.println("not executable");
      }
   }
}
Posted by: Guest on July-08-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language