Java Files check file existence follow/not follow links

Description

Java Files check file existence follow/not follow links

import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
   public static void main(String[] args) {
      Path firstPath = Paths.get("/home/java/users.txt");
      System.out.println("exists (Do not follow links): " + Files.exists(firstPath, LinkOption.NOFOLLOW_LINKS));
      System.out.println("exists: " + Files.exists(firstPath));
      System.out.println("notExists (Do not follow links): " + Files.notExists(firstPath, LinkOption.NOFOLLOW_LINKS));
      System.out.println("notExists: " + Files.notExists(firstPath));
   }//  w w w .  j  av  a  2  s.c o  m
}



PreviousNext

Related