Java Path create from URI

Description

Java Path create 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  ww . j av  a2  s . com*/
    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