Determine if a file can be read - Java File Path IO

Java examples for File Path IO:File Operation

Description

Determine if a file can be read

Demo Code


import java.io.File;

public class Main {

  public static void main(String[] args) {
    String filePath = "C:/Folder/ReadText.txt";

    File file = new File(filePath);
    if (file.canRead()) {
      System.out.println("File " + file.getPath() + " can be read");
    } else {/*from w  ww  . j a v a 2  s .  c  o  m*/
      System.out.println("File " + file.getPath() + " can not be read");
    }
  }
}

Result


Related Tutorials