集册 Java实例教程 确定是否可以读取文件

确定是否可以读取文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

477
确定是否可以读取文件


import java.io.File;
/**时 代 J a v a 公 众 号 - nowjava.com**/

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 {

      System.out.println("File " + file.getPath() + " can not be read");

    }

  }

}