File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes duplicate file detection on hard-disk by java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "duplicate file detection on hard-disk by java" Watch "duplicate file detection on hard-disk by java" New topic
Author

duplicate file detection on hard-disk by java

rajat mandaniyan
Greenhorn

Joined: Sep 13, 2008
Posts: 6
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 ]

rohit
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3534
    
  15
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.


Joanne
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10363
    
    8

Sounds like an assignment/home work.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 347
Would the generation of a hash help here?
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4655
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: duplicate file detection on hard-disk by java