Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

duplicate file detection on hard-disk by java

 
rajat mandaniyan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) please can anybody help me on HOW TO DETECT DUPLICATE FILE ON HARD-DISK USING JAVA LANGUAGE
... on the basis of contents of file

2) please help me over the concept & also provide the code for it
[ September 19, 2008: Message edited by: rajat mandaniyan ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by a duplicate file - a file with the same name or a file with the same name and same content ?

If the former you can use the File, FilenameFilter and FileFilter classes to list all the files in a directory with a given name.
If you need to check the content as well, then you need to look at the Java I/O tutorial.

Nobody here will just give you the code, you need to show some effort. Hava a look at the suggestions above and then see what you can come up with. If you have any problems show us what you have tried and give us full details of the problem.
See the HowToAskQuestionsOnJavaRanch FAQ for more details.
 
Maneesh Godbole
Saloon Keeper
Posts: 11070
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like an assignment/home work.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Joanne said, you will have to compare the full contents. However, you can use the file length() first as a shortcircuit check - if the lengths are different, the files most certainly are.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would the generation of a hash help here?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gamini Sirisena:
Would the generation of a hash help here?


That is the normal way to do it. Checking lengths, etc. is not going to tell anything.

Run it through MD5 of sha1, store the result in a HashMap, and you are all set.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic