|
Java™ by example!
|
|
|
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!
|
|
|
|
|