In this article, we'll introduce how to compare two Word documents and find the differences between them by using Spire.Doc for Java.
The input Word documents look as follows:
import com.spire.doc.Document; public class CompareWordDocuments { public static void main(String[] args) throws Exception { //Create a Document instance Document doc1 = new Document(); //Load the first Word document doc1.loadFromFile("Doc1.docx"); //Create a Document instance Document doc2 = new Document(); //Load the second Word document doc2.loadFromFile("Doc2.docx"); //Compare the two Word documents doc1.compare(doc2, "E-iceblue"); //Save the result to file doc1.saveToFile("Result.docx"); } }
Output: