Combine isReadable(), isWritable(), and isExecutable() methods - Java File Path IO

Java examples for File Path IO:File Operation

Description

Combine isReadable(), isWritable(), and isExecutable() methods

Demo Code

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
  public static void main(String[] args) {
    Path path = FileSystems.getDefault().getPath(
        "C:/folder1/folder2/folder4", "test2.txt");

    boolean is_accessible = Files.isRegularFile(path) & Files.isReadable(path)
        & Files.isExecutable(path) & Files.isWritable(path);
    if (is_accessible) {
      System.out.println("The checked file is accessible!");
    } else {//w  w w .  ja v a  2s .  c  om
      System.out.println("The checked file is not accessible!");
    }

  }
}

Result


Related Tutorials