What easy technique shall i use in developing a java program that will output to screen or to a file

B

bronby

hi guys!
i wish someone could help me out on this.
just started learning java lately.

i have to develop a program that will detect (be it in screen or a .txt
file) if file(s) had been changed (or added, deleted) inside a specific
directory...

any suggestions? technique?
and what java language functions to suggest that would best fit my prog.
requirements?

hope to hear from u guys..
thanks.
 
J

Johan Poppe

bronby said:
i have to develop a program that will detect (be it in screen or a .txt
file) if file(s) had been changed (or added, deleted) inside a specific
directory...

any suggestions? technique?

Have a look at java.io.File. This will give you both contents of a
directory and modification date for individual files.
 
B

bronby

i mean shall i create an loop
like a do { } while { } loop which detects
infinitely if a file has been added or changed in that specific
directory?
 
J

Johan Poppe

bronby skrev:
i mean shall i create an loop
like a do { } while { } loop which detects
infinitely if a file has been added or changed in that specific
directory?

You have to check repeatedly, yes. Unless you want your program to hog
all CPU power, you should include a sleep() in that loop. And put the
loop in a separate thread.
 
B

bronby

like this one?

int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// Task here ...
//checking of files using
//java.io.file .. routines etc..
}
}, delay, period);


is this a thread too?
 
J

Jacob

bronby said:
i have to develop a program that will detect (be it in screen or a .txt
file) if file(s) had been changed (or added, deleted) inside a specific
directory...

The "filemonitor" module of http://geosoft.no/software/ does
exactly this. You may use it as is, or look at the implementation
for inspiration.

In your particular case you will monitor the _directory_ and you
will be notified whenever anything happens inside that directory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top