To take action only if the file does not exist, call the notExists() method - Java File Path IO

Java examples for File Path IO:File Operation

Description

To take action only if the file does not exist, call the notExists() method

Demo Code

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.LinkOption;
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 });

  }//from w  w w .  j ava2s  .  c  o  m
}

Related Tutorials