集册 Java实例教程 只在文件不存在时才采取行动,调用

只在文件不存在时才采取行动,调用

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

411
要仅在文件不存在时采取措施,请调用notExists()方法

import java.nio.file.FileSystems;

import java.nio.file.Files;

import java.nio.file.LinkOption;/** from NowJava.com - 时  代  Java**/

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 path_notexists = Files.notExists(path,

        new LinkOption[] { LinkOption.NOFOLLOW_LINKS });


  }

}