File toURI() Example
Constructs a file: URI that represents this abstract pathname
File class toURI() method example. This example shows you how to use toURI method.This method Constructs a file: URI that represents this abstract pathname
Here is the code:-
/**
* @Program that Constructs a file: URI that represents this abstract pathname.
* toURI.java
* Author:-RoseIndia Team
* Date:-31-May-2008
*/
import java.io.*;
import java.net.*;
public class toURI {
public static void main(String[] args)throws IOException {
File f = new File("/home/girish/Desktop/girish.txt");
URI uri = f.toURI();
if (f.exists()) {
System.out.println("URI representation of path is : "+uri.toString());
} else {
System.out.println("File cannot exists: ");
}
}
} |
Output of the Program
| URI representation of path is : file:/home/girish/Desktop/girish.txt |
|