0% found this document useful (0 votes)
12 views4 pages

Practical 14

The document contains code for a Java program that demonstrates how to get information from URLs using classes like URL, URLConnection, and InetAddress. It shows how to get the host name, protocol, port number, file from a URL. It also shows how to get metadata like date, content type, length from the URLConnection and read/print the content from the input stream. The program outputs various details when run on sample URLs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Practical 14

The document contains code for a Java program that demonstrates how to get information from URLs using classes like URL, URLConnection, and InetAddress. It shows how to get the host name, protocol, port number, file from a URL. It also shows how to get metadata like date, content type, length from the URLConnection and read/print the content from the input stream. The program outputs various details when run on sample URLs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

//**************** (Practical 14) XIII(1) ********************

import java.net.*;
import java.util.Scanner;

public class Practical1


{
public static void main(String a[])throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("enter the Host name : ");
String h_name = sc.next();
InetAddress ia = InetAddress.getByName(h_name);
System.out.println("IP Address = "+ia);

/*
//OUTPUT :

enter the Host name : google.com


.IP Address = google.com/142.250.192.78

*/
//**************** (Practical 15) XIII(1) ********************

import java.net.*;
import java.util.Scanner;

public class Practical1


{
public static void main(String a[])throws Exception
{
URL url1 = new URL("http://www.msbte.org.in");
System.out.println("Host Name = "+url1.getHost());
System.out.println("Protocol = "+url1.getProtocol());
System.out.println("port number = "+url1.getPort());
System.out.println("File = "+url1.getFile());

}
}

/*
OUTPUT :
Host Name = www.msbte.org.in
Protocol = http
port number = -1
File =

*/
//******************** (Practical 15) XIII(2)
************************

import java.io.InputStream;
import java.net.*;
import java.util.Date;

public class Practical1


{
public static void main(String a[])throws Exception
{
int i;
URL url1 = new URL("http://www.msbte.org.in");
URLConnection urlc = url1.openConnection();

System.out.println("Date = "+new Date(urlc.getDate()));


System.out.println("Content type = "+urlc.getContentType());
System.out.println("Content length =
"+urlc.getContentLength());
System.out.println("Content = ");

if(urlc.getContentLength()!=0)
{
InputStream is = urlc.getInputStream();

while ((i=is.read())!=-1)
{
System.out.print((char)i);
}

}
else
{
System.out.println("there is no content present in this
site...!");
}

}
}

/*
OUTPUT =
Date = Mon Oct 09 22:03:02 IST 2023
Content type = text/html
Content length = 524077
Content =


<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Maharashtra State Board of Technical Education, Mumbai
, India</title>
<meta https-equiv="content-language" content="en-US">
<meta name="language" content="English">
<meta name='google-site-verification' content='Maharashtra
State Board of Technical Education, Mumbai' />
.
.
.
.
.
.
<button onclick="topFunction()" class="scrollup" id="myBtn"
title="Go to top"><img
src="https://msbte.org.in/slide/img/Maharashtra-State-Board-of-
Technical-Education--Mumbai.jpg" alt="ScrollTop"></button>

<!-- container ends here -->


</body>

</html>

*/

You might also like