You are on page 1of 2

M.M.

Polytechnic, Thergaon

//Exp151
import java.net.*;
import java.io.*;

public class exp151


{
public static void main(String [] args)
{
try
{
URL url = new URL("http://www.msbte.com");

System.out.println("Protocol is:\t " + url.getProtocol());


System.out.println("Port is:\t " + url.getPort());
System.out.println("Host is:\t " + url.getHost());
System.out.println("File name is:\t " + url.getFile());

}catch(IOException e)
{
System.out.println(e);
}
}
}

//Exp152
import java.net.*;
import java.io.*;
import java.util.Date;
class exp114
{
public static void main(String args[]) throws Exception
{
int c;
URL hp = new URL("http://www.java-samples.com/");
URLConnection hpCon = hp.openConnection();
System.out.println("Date: " + new Date(hpCon.getDate()));
System.out.println("Content-Type: " + hpCon.getContentType());
int len = hpCon.getContentLength();
System.out.println("Content-Length: " + len);
if (len > 0)
{
System.out.println("=== Content ===");

AJP Expt-15 1 Mrs. Chavan P.P.


M.M.Polytechnic, Thergaon

InputStream input = hpCon.getInputStream();


int i = len;
while (((c = input.read()) != -1) && (i > 0))
{
System.out.print((char) c);
}
input.close();
}
else
{
System.out.println("No Content Available");
}
}
}

AJP Expt-15 2 Mrs. Chavan P.P.

You might also like