Convert a Path to a URI - Java File Path IO

Java examples for File Path IO:Path

Introduction

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

Demo Code

import java.net.URI;
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  w  w .ja va2 s .c  o  m*/
}

Result


Related Tutorials