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