import java.io.*;
import java.net.*;
* Created on Feb 20, 2003
*/
public class ReadContentsOfURL{
public static void main(String[] args) throws Exception
{
// create a URL object and open a stream to it
URL httpUrl = new URL("http://www.weather.com/weather/local/94539?lswe=94539");
InputStream istream = httpUrl.openStream();
// convert stream to a BufferedReader
InputStreamReader ir = new InputStreamReader(istream);
BufferedReader reader = new BufferedReader( ir );
// then read the contents of the URL through a BufferedReader
StringBuffer buf = new StringBuffer();
int nextChar;
while( (nextChar = reader.read()) != -1 )
{
buf.append( (char)nextChar );
}
// close the reader
reader.close();
System.out.println( buf );
}
}
No comments:
Post a Comment