I've spent a lot of my career as a software engineer working with Unix or Linux operating systems. Whenever I've had two files with just minor differences between them, I could type in at the command prompt:
diff file1.Txt file2.Txt
and I'd get a listing of all the differences between the two files, looking something like:
< the quick brown fox jumps over the lazy dog
> the quick brown fox jumped over the lazy dogs
However, now I'm stuck with Windows 7, that, as far as I know, doesn't have an analogous diff command (correct me if I'm wrong). In a situation like this, it would be very nice if there existed a Java program itself that would do more or less what the Unix diff did for me before. Part of me is tempted to try to write such a Java program, but before I did that I thought I should probably come to this forum and ask everyone if such a Java program already exists. No sense reinventing the wheel. Does anybody know of any such Java program?
I took a look at Nicholas Butler's description of Myer's algorithm for use in finding the differences between two character arrays, in the hopes that I could use it to find the differences between two string arrays, and thus find the differences between two files. That description is at "http://www.codeproject.com/Articles/42279/Investigating-Myers-diff-algorithm-Part-of". I was following what he was saying until he got to the subsection labeled "d contours" under section "Definitions". Does anyone else understand what a "d contour" is in light of the other definitions?
Not far down from there Butler lists code that looks like C# in what he calls "the core implementation":
and another section he calls the "solution":
but it's not clear how these two pieces fit together, even if they could be translated into Java. Anybody have any ideas?
I finally found a Java program that does exactly what I needed the "diff" utility to do, at URL "introcs.cs.princeton.edu/java/96optimization/Diff.java.html". I modified it slightly to do what I wanted it to do, and to fit my style, and came up with:
Feel free to try it out. I should warn you that if the files you are comparing both have much more than ten thousand lines, this program runs out of Java heap space.