You are on page 1of 2

Program 4.7.1: | Write a program that demonstrate the use of URL class and its methods.

import java.io.*;
import java.net.*;
class URLDemo

{
public static void main (String ar[ ]) throws IOException
ifL

String st = “http://admissions.puchd.ac.in/”
if (st.Jength != 1)
{
System.err.println ("usage: java URLDemo wr") >
.

————————

W TechKnowled
pubsicacler!

Scanned with CamScanner


LW Advanced Java Programming (MSBTE) 4-13 Networking Basics
————————— ==

retum;

}
URL url = new URL (st):
System.out.println ("Authority = "+ url.getAuthority());
System.out.printn ("File = ‘ +url.getFile( ));
System.out.printin ("Host = " +url.getHost( ));
System.out.printn ("Path = " +url.getPath( )):
System.out.prinun ("Port = " +url.getPorti }):
System.out.prinun ("Protocol = " +url.cetProtocol( ));
System.out.printin ("Query = " +url.getQuery( ));
System.out.printIn ("Ref = “ +url.getRel( });
System.out.println ("User Info = " +url.getUserInfo( }):
System.out.print (‘\n'):
InputStream is = url.openStream( ):
int ch;
while ((ch = is.read ()) != -1)
System.out.print ((char) ch);
is.close ();
——

Scanned with CamScanner

You might also like