how to write a program to download data from website to a local machine.

Hi,

is it possible to download data like 1- 1000 numbers from a website into a java program in my local machine and execute the java program on the local machine.If yes then how can i pass this data ? can it be passed one by one or at bulk through a file? how doe my local program capture this data ? is there any way to do this.

Any help is highly appreciated.

thanks,

lsk.

[405 byte] By [suryakula] at [2007-11-27 11:29:19]
# 1

If I understand your question, you have an URL to the page where your numbers are. Then you can go like this:

BufferedReader reader = new BufferedReader(new InputStreamReader(sourceURL.openStream()));

You basically use the reader to get the source code of the page. How you'll parse the HTML you get to extract the data you want is another issue, and it depends on the layout of the page itself.

I hope this helps.

Time_Agentessa at 2007-7-29 16:27:14 > top of Java-index,Desktop,Developing for the Desktop...
# 2

Thanks for the reply .But my doubt is if i were to download the set of numbers like 1,2,3,4,5.which are stored in a file and then i download this file to loaclhost from my website .How can my java program recognise that some file is downloaded .Then my java program should start reading this numbers .

i hope the question is clear now.

suryakula at 2007-7-29 16:27:14 > top of Java-index,Desktop,Developing for the Desktop...
# 3

In java there is a nice patterns called events.

what you do is simply create

1. Event object - describes the event which in your case is "file created". The event can store for example the file name and such (up to you as this is your own class)

2. Event listener - with a method I suppose in your case would befileCreated(Event event);

3. Listener implementation - Implement the listener to do any special handling you want when the event is thrown meaning a file is created

4. Event Source - This is the source of the events which i guess would be the class that downloaded the file from the web and wrote it to the file system.

So what you will have is that the event listener would register itself in the event source. When the event source downloads a file it should then create an event and activate the fileCreated method in all listeners it has. The listeners then do any special handling you want.

sushika at 2007-7-29 16:27:14 > top of Java-index,Desktop,Developing for the Desktop...