0% found this document useful (0 votes)
2 views

java practical 24 (1)

This Java program demonstrates how to establish a connection to a URL and retrieve various details about the connection, such as content type, last modified date, and headers. It also reads and prints the complete source code of the specified URL. The program handles exceptions that may occur during the connection process.

Uploaded by

bhatsoham5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java practical 24 (1)

This Java program demonstrates how to establish a connection to a URL and retrieve various details about the connection, such as content type, last modified date, and headers. It also reads and prints the complete source code of the specified URL. The program handles exceptions that may occur during the connection process.

Uploaded by

bhatsoham5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Practical No.

24
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class URLConnectionDemo ,


public static void main(String args*+) ,
try ,
URL url = new URL("https://msbte.org.in");
URLConnection urlcon = url.openConnection();

System.out.println(urlcon.getAllowUserInteraction());
System.out.println(urlcon.getContentType());
System.out.println(urlcon.getURL());
System.out.println(urlcon.getDoInput());
System.out.println(urlcon.getDoOutput());
System.out.println(new Date(urlcon.getLastModified()));
System.out.println(urlcon.getContentEncoding());

Map<String, List<String>> header = urlcon.getHeaderFields();


for (Map.Entry<String, List<String>> mp : header.entrySet()) ,
System.out.println(mp.getKey() + ":");
System.out.println(mp.getValue().toString());
-

System.out.println();
System.out.println("Complete source code of the URL is-");
System.out.println("------------------------------------");

BufferedReader br = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));


String i;
while ((i = br.readLine()) != null) ,
System.out.println(i);
-
- catch (Exception e) ,
System.out.println(e);
-
-
-

You might also like