checking file writable java

Solutions on MaxInterview for checking file writable java by the best coders in the world

showing results for - "checking file writable java"
Samuel
28 Sep 2017
1import java.nio.file.Files;
2import java.nio.file.Path;
3import java.nio.file.Paths;
4public class FilesExample {
5   public static void main(String args[]) {
6      //Creating a Path object
7      Path path = Paths.get("D:\\sample.txt");
8      //Verifying if the file is readable
9      boolean bool = Files.isReadable(path);
10      if(bool) {
11         System.out.println("readable");
12      } else {
13         System.out.println("not readable");
14      }
15      bool = Files.isWritable(path);
16      if(bool) {
17         System.out.println("writable");
18      } else {
19         System.out.println("not writable");
20      }
21      bool = Files.isExecutable(path);
22      if(bool) {
23         System.out.println("executable");
24      } else {
25         System.out.println("not executable");
26      }
27   }
28}