Java Path.toUri()

Syntax

Path.toUri() has the following syntax.

URI toUri()

Example

In the following code shows how to use Path.toUri() method.


import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
//from w w  w . ja va2  s .  c o  m
public class Main {

    public static void main(String[] args) {

        Path path = Paths.get("C:", "tutorial/Java/JavaFX", "Topic.txt");
        //convert path to an URI (browser format)
        URI path_to_uri = path.toUri();
        System.out.println("Path to URI: " + path_to_uri);
    }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService