Difference between two files

Hi, I need to find difference between two files.

This is an example:

oldfile.txt:

This is the old file.

Ineed some help with

this task!.

newfile.txt:

This is the new file.

I need help with this task please!.

Differences:

* old -> new

*need -> need

* "some" was deleted

* please was added

Notice that I don't care spaces, new lines or tabs.

The code should looks like:

enum DifferenceType{ Added, Deleted, Replaced};

class DiffText{

public String Text;

public DifferenceType Type;

public String ReplacedText;

};

//...

Diff d =new Diff("oldfile.txt","newfile.txt");

while(!d.end()){

DiffText dtext = d.getNext();

String s ="";

switch(s.Type){

case Added:System.out.println(s.Text +" ~ added");

case Deleted:System.out.println(s.Text +" ~ deleted");

case Replaced: System.out.println(s.Text +" replaced by " + s.ReplacedText);

}

}

Thanks for your help in advance.

[1859 byte] By [lucaz_a] at [2007-10-1 17:59:32]
# 1
What is your question?
yawmarka at 2007-7-11 12:35:19 > top of Java-index,Other Topics,Algorithms...
# 2
Sorry, my question was:The Diff class doesn't exist, do you know something similar?
lucaz_a at 2007-7-11 12:35:19 > top of Java-index,Other Topics,Algorithms...
# 3

Suppose you have two arrays filled with integers.

What you want to do is map the integers from one

array to the other.

In your example, your arrays would look like:

this is the old file i need some help with this task

[01 234 56789010]

this is the new file i need help with this task please

[01 2114 568901012]

Here, I've assumed you've removed all punctuation and

new line characters, and changed to lowercase.

The easiest way is to walk through the arrays greedily.

However, you may be able to research algorithms that

do a better job of matching.

rkippena at 2007-7-11 12:35:19 > top of Java-index,Other Topics,Algorithms...
# 4
What about google ?There is GNU Diff algorithm in Java at http://bmsi.com/java/
martin.pawlasa at 2007-7-11 12:35:19 > top of Java-index,Other Topics,Algorithms...
# 5
Levenshtein might help you. http://www.google.com/search?hl=en&q=levenshtein
Ragnvald_id2a at 2007-7-11 12:35:19 > top of Java-index,Other Topics,Algorithms...