Java IO Tutorial - Java File.toURI()








Syntax

File.toURI() has the following syntax.

public URI toURI()

Example

In the following code shows how to use File.toURI() method.

//w  w  w. ja  v  a 2  s.  c om
import java.io.File;
import java.net.URI;

public class Main {
  public static void main(String[] args) {
    File f = new File("c:/a/b/a/test.txt");

    // returns the uri string
    URI uri = f.toURI();

    System.out.println("uri: " + uri);

  }
}

The code above generates the following result.