Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file comparison

 
Rashmi Trivedi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 servlet...so that my collegue can check things on the web as well...
would you be able to help me guys...
your time is much appreciated...
regards,
Rashmi
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rashmi Trivedi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
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...

regards,
Rashmi
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a Servlet question, I'll move it to Java in General (intermediate) for you.
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic