集册 Java实例教程 确定文件或目录是否存在

确定文件或目录是否存在

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

400
确定文件或目录是否存在
/* 来自 nowjava.com - 时代Java*/

import java.io.File;


public class Main {

  public static void main(String[] args) {

    boolean exists = (new File("filename")).exists();

    if (exists) {

      // File or directory exists

    } else {

      // File or directory does not exist

    }

  }

}