• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to find Difference between two files in java

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need information regarding How to find out difference between two files in java interms of Modified Lines ,newly Added lines nad deleted lines.
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may be of interest: http://www.bmsi.com/java/#diff

Remember to read the licence stuff!

Having read your other post, I'm not sure if you are trying to find the difference between two java source files, or write a java program to find the difference between to arbitrary files?
[ February 25, 2005: Message edited by: Horatio Westock ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an algorithm I found. The code was a literal translation of C to Java, very nasty. I did my own implementation that is slightly less nasty. I'd be happy to share the code if you're not doing a school assignment, but you might have more fun exploring on your own.

For each each unique line of text create a symbol. Two lines that are equals() share a symbol. The symbol state is: OldOnly, NewOnly, UniqueMatch (both files exactly once), or Other.

For each line, create a LineInfo object. Set state = symbol state and establish bidirectional links between UniqueMatch lines in the two files.

For each UniqueMatch in old create a "match block". Stretch match blocks forward and backward to include matching lines with any state, including other match blocks.

Build a Report of edit commands that can be used to tranform Old into New. Matching blocks generate match or move commands. Non-matching blocks generate insert, append, delete or change commands. (this is the triky bit, but only 14 lines of code.)

Iterate the commands to generate a report.

Edit: Just remembered I had a web page on this: Text Diff. The zip of my source is missing in action - sorry about that. The link to the code I read for the algorithm is there but I would not advise copying any of it.
[ February 25, 2005: Message edited by: Stan James ]
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anyone cares, I fixed the link to the source zip: TextDiff.zip.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://javacook.darwinsys.com/javasrc/textproc/Diff.java - Cached

Great Java Diff
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the link, which I converted to a hyperlink. And welcome to the Ranch
 
Well THAT's new! Comfort me, reliable tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic