esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I get the contents of a URL?



import java.net.*;
import java.io.*;

class UrlDemo1
{
public static void main(String [] args)
{
try
{
// step1: make a url object
URL u=new URL("http:/C:/lbs/first.html");

// step2: make a file object
// using the getFile method of the url class
File f=new File(u.getFile());
System.out.println(f.getName());//verify the name
System.out.println(f.exists());//verify if the file exists

// step3: start a datainputstream and
// read from it and print
DataInputStream dis =new DataInputStream(new FileInputStream (f));
while(dis.readLine()!=null)
System.out.println(dis.readLine());
}
catch(Exception e)
{
System.out.println(e);
}
}
}




Further Information
Author of answer: shravani

Comments
Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.