Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:
Donate to VoyForums (PayPal):
[ Login ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1, 2, 3, 4, 5, 6, 7, 8, [9] ] |
import java.net.*;
import java.io.*;
public class WebReader
{
/********/
/*FIELDS*/
/********/
private URL url;
private StringBuffer out;
/***********/
/*ACCESSORS*/
/***********/
public URL getUrl()
{
return url;
}
public void setUrl(URL url)
{
this.url = url;
}
public StringBuffer getOut()
{
return out;
}
public void setOut(StringBuffer out)
{
this.out = out;
}
/****************/
/*HELPER METHODS*/
/****************/
public void read()
{
//declare streams
InputStream in = null;
BufferedInputStream bin = null;
DataInputStream din = null;
//create streams
try
{
in = getUrl().openStream();
bin = new BufferedInputStream(in);
din = new DataInputStream(bin);
System.out.println("Streams created");
String line;
while( (line = din.readLine()) != null )
{
getOut().append(line).append('\n');
}
System.out.println("Lines all read");
}
catch(IOException ioe)
{
System.err.println(ioe);
}
finally
{
//kill streams, no matter what happened
try
{
if(din != null)
{
din.close();
din = null;
}
System.out.println("\"din\" is closed");
if(bin != null)
{
bin.close();
bin = null;
}
System.out.println("\"bin\" is closed");
if(in != null)
{
in.close();
in = null;
}
System.out.println("\"in\" is closed");
}
catch(IOException ioe)
{
System.err.println(ioe);
}
}
}
/**************/
/*CONSTRUCTORS*/
/**************/
public WebReader(URL url)
{
setUrl(url);
setOut(new StringBuffer());
}
/*********/
/*STATICS*/
/*********/
public static String readFromWeb(URL url)
{
WebReader wr = new WebReader(url);
wr.read();
return wr.getOut().toString();
}
}
Forum timezone: GMT-5 VF Version: 3.00b, ConfDB: Before posting please read our privacy policy. VoyForums(tm) is a Free Service from Voyager Info-Systems. Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved. |