The toURI() method of File class is used to get the URI reference.
Example:
package com.w3schools;
import java.io.File;
public class FileURI {
public static void main(String args[]){
File file = new File("D:/Test files/file 3.txt");
System.out.println(file.toURI());
}
} |
package com.w3schools;
import java.io.File;
public class FileURI {
public static void main(String args[]){
File file = new File("D:/Test files/file 3.txt");
System.out.println(file.toURI());
}
}
Output:
file:/D:/Test%20files/file%203.txt |
file:/D:/Test%20files/file%203.txt
Download this example.