checking file writable java code example

Example: 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");
      }
   }
}

Tags:

Java Example