Convert Path to URI in Java

Description

The following code shows how to convert Path to URI.

Example


import java.nio.file.Path;
import java.nio.file.Paths;
/*w ww  .  ja  v a 2 s  .c o m*/
public class Main {

  public static void main(String[] args) throws Exception {
    Path path = Paths.get("users.txt");

    System.out.println("URI path: " + path.toUri());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode