Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to diff files in java  RSS feed

 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want the soultion using java.I have a file(let's say test.txt) which will be stored in current_files directory. Whenever I get new file(means same file with new version), I will move the file(test.txt) to old_files directory and replace the existing file with new file.But before do this I just want to compare both files are same are not .Can anybody tell me which is easier and best way to compare files to know whether both files contents are same are not ?
Regards
Raju
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Easiest and best" depends on your program requirements. Want a real fast but maybe not very accurate test? Compare file length. Real slow but real accurate? Read the files and compare line by line. Compromise? Perform a checksum of the files and compare the checksum. java.util.zip.CheckedInputStream does such a thing.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!