How to get file URI reference in java?.

How to get file URI reference in java?.

Below example shows how to get URl reference to the given file. By calling toURl() method on file object, you can get the URl reference.

The following URLDemo program demonstrates the various parts of a URL.
 

import java.net.*;

import java.io.*;

public class URLDemotest    {

public static void main(String [] args)

{

try    {

URL url = new URL("http://www.java.com/myjava?language=j2se");

System.out.println("URL is " + url.toString());

System.out.println("protocol is "

+ url.getProtocol());

System.out.println("authority is "

+ url.getAuthority());

System.out.println("file name is " + url.getFile());

System.out.println("host is " + url.getHost());

System.out.println("path is " + url.getPath());

System.out.println("port is " + url.getPort());

System.out.println("default port is "

+ url.getDefaultPort());

System.out.println("query is " + url.getQuery());

System.out.println("ref is " + url.getRef());

}catch(IOException e)

{

e.printStackTrace();

}}}

Read More →