Example & Tutorial understanding programming in easy ways.

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 →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!