Java Paths get Path from URI

Description

Java Paths get Path from URI

import java.net.URI;
import java.net.URISyntaxException;
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 path;/*from   w  w w  .  j  a v a2 s  . c o  m*/
    try {
      path = Paths.get(new URI("file:///C:/home/docs/bogusfile.txt"));
      System.out.println("File exists: " + Files.exists(path)); 
    } catch (URISyntaxException e) {
      e.printStackTrace();
    } 
  }
}



PreviousNext

Related