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

Url Header

This Java program opens a URL connection to a local file, retrieves header information about the file such as content type, encoding, dates, and length, and prints it out. It catches any URL or IO exceptions and prints those out.

Uploaded by

anon-759825
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Url Header

This Java program opens a URL connection to a local file, retrieves header information about the file such as content type, encoding, dates, and length, and prints it out. It catches any URL or IO exceptions and prints those out.

Uploaded by

anon-759825
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

URL HEADER

import java.net.*;
import java.io.*;
import java.util.*;
public class urlhdr
{
public static void main(String args[])
{
try
{
URL u = new URL("file:\\d:\\rectarea2.java");
URLConnection uc=u.openConnection ();
System.out.println ("Content type:"+uc.getContentType ());
System.out.println ("Content encoding:"+uc.getContentEncoding ());
System.out.println ("Date:"+new Date (uc.getDate ()));
System.out.println ("Last Modified:"+new Date(uc.getLastModified()));
System.out.println ("Expiraton Date:"+new Date(uc.getExpiration()));
System.out.println ("Content Length:"+uc.getContentLength ());
}
catch (MalformedURLException ex)
{
System.out.println (ex);
}
catch(IOException e)
{
System.out.println(e);
}
System.out.println();
}
}

Output:

Content type:text/plain
Content encoding:null
Date:Thu Jan 01 05:30:00 GMT+05:30 1970
Last Modified:Sat Sep 06 15:00:48 GMT+05:30 2008
Expiraton Date:Thu Jan 01 05:30:00 GMT+05:30 1970
Content Length:503

You might also like