Wednesday, August 12, 2009

How can i read data from any URL, which can bea binary data or from a Active Server Page ?

Using the Following code, you can download any data. If it connects to either Servlet or ASP page, then the data get's processed if required and the resultant data is read back.

//Connect to any URL, can be to a image, to a static URL like www.yahoo.com or any ASP page.
URL url = new URL("http://www.aspkit.com/jdata/transaction/transact.asp");

URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
FileOutputStream file = new FileOutputStream("result.txt");
BufferedOutputStream out = new BufferedOutputStream(file);

//Reading Data from the above URL
int i; while ((i = in.read()) != -1){
out.write(i);
}

No comments:

Post a Comment