Performing a simple diff on 2 non git files with the jgit library:
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.diff.HistogramDiff;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.diff.RawTextComparator;
public class RawDiff
{
public static void main(String[] args) throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
try
{
RawText rt1 = new RawText(new File("C:\\temp\\twofiles\\file1.txt"));
RawText rt2 = new RawText(new File("C:\\temp\\twofiles\\file2.txt"));
EditList diffList = new EditList();
diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2));
new DiffFormatter(out).format(diffList, rt1, rt2);
} catch (IOException e)
{
e.printStackTrace();
}
System.out.println(out.toString());
}
}