Java Path interface

Description

Java Path interface

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String args[]) {
    Path filepath = Paths.get("examples\\test.txt");

    System.out.println("File Name: " + filepath.getName(1));
    System.out.println("Path: " + filepath);
    System.out.println("Absolute Path: " + filepath.toAbsolutePath());
    System.out.println("Parent: " + filepath.getParent());

    if (Files.exists(filepath))
      System.out.println("File exists");
    else/*from  ww w  .  j  av  a 2  s . c om*/
      System.out.println("File does not exist");

    try {
      if (Files.isHidden(filepath))
        System.out.println("File is hidden");
      else
        System.out.println("File is not hidden");
    } catch (IOException e) {
      System.out.println("I/O Error: " + e);
    }
  }
}



PreviousNext

Related