Convert a Path to a URI - Java File Path IO

Java examples for File Path IO:Path


You can convert a Path to a web browser format string by applying the toURI() method.

Demo Code

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

public class Main {
  public static void main(String[] args) {
    Path path = Paths.get("/folder1/folder2/folder4", "test.txt");

    URI path_to_uri = path.toUri();  
    System.out.println("Path to URI: " + path_to_uri);  
  }/*from   w  ww . j  av  a2 s. com*/


Related Tutorials