Two Laptop Bag
The moose likes Java in General and the fly likes file comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "file comparison" Watch "file comparison" New topic

file comparison

Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Hi Guys
I am kind of stuck now..this is what i would my program to do...
I want to compare two different direcotries and compare the files in those direcotries...and write a log saying this is what missing...
in my case there will be a two direcotry A and B
A will have the most latest files and i will be comparing A to other direcotries to check the update...
I am planning to write a that my collegue can check things on the web as well...
would you be able to help me guys...
your time is much appreciated...
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can use a File object to get a list of files in a directory. You'll probably have a recursive routine that calls itself to deal with subdirectories.
I'd build myself a structure that holds the sorted contents of one directory, maybe a TreeSet of File objects with a Comparator to get them in path plus name order. Create two of these, one for directory A and another for directory B.
Then I'd build something to pull elements from these two sets with a classic sorted set comparison routine:

I'd probably put the result of each trip through this loop into a little object with a flag for A-only, B-only, Both-match, Both-date or size mismatch, and put all of those into yet another structure.
Note - no Servlet stuff here yet. You could use this from a fat Java client and unit test it separately. Finally, pull that collection of result objects into your servlet or JSP page and write out the results.
Any of that help?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
i must admit that this is not very clear to me...i will try my own things till i have break through...
thank you for your time...i do appreciate it...

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

This is not a Servlet question, I'll move it to Java in General (intermediate) for you.
I agree. Here's the link:
subject: file comparison
It's not a secret anymore!