Compare Word files in Java

Powerful Java library to compare Word documents and detect even small differences

Compare two Word files in Java using our difference checker. With our high-fidelity Java API, you can find the difference between compared Word documents and export the results to a convenient file format.

How Word Compare works

Comparing documents is a rather difficult function to implement. But our Java solution is designed so that you can get the most accurate result.

To compare two Word documents, our powerful Java library compares content at both the character level and word level. If only a character has been changed, the word will be marked as the whole changed.

This way you can no longer look for differences in documents manually, but instead use our Java API to compare documents.

Compare Word files using Java

Sometimes you are not sure if a document has not been modified, and comparing two document versions manually can be tricky. Or vice versa, you know for sure that the document has been changed, but manually searching for updated places is too hard.

In all these situations and more, you can diff two Word files using our product API. To compare two documents, simply load them, call the comparison method, and get the result in a convenient file format. This allows you to find even small changes that would be invisible to the human eye.

Compare two Word documents

To compare Word s and verify how our Java library works, simply load the files you want to diff and select the export file format. After comparing two files, the document containing the difference of this comparison will be automatically loaded.

An important point: the compared documents should not have any revisions before calling the comparison method. And it is necessary to accept all revisions, which we have already taken care of in our example:

Compare two DOCX files using Java
Input files
Upload the compared file
Run code
Upload the second file to compare
Output format
Select the target format from the list
import com.aspose.words.*;

Document docA = new Document("Input1.docx");
Document docB = new Document("Input2.docx");

// There should be no revisions before comparison.
docB.acceptAllRevisions();, "Author Name", new Date());"Output.docx");
Run code

How to compare two Word in Java

  1. Install 'Aspose.Words for Java'
  2. Add a library reference (import the library) to your Java project
  3. Load two Word to compare
  4. Accept all revisions before calling the 'compare()' method
  5. Call the 'compare()' method to compare two Word
  6. Call the 'Save()' method, passing an output filename with required extension
  7. Get the result of compression Word as a separate file

Java library to compare Word documents

We host our Java packages in Maven repositories. 'Aspose.Words for Java' is a common JAR file containing byte-code. Please follow the step-by-step instructions on how to install it to your Java developer environment.

System Requirements

Java SE 7 and more recent Java versions are supported. We also provide a separate package for Java SE 6 in case you are obliged to use this outdated JRE.

Our Java package is cross-platform and runs on all operating systems with JVM implementation, including Microsoft Windows, Linux, macOS, Android and iOS.

For information on optional package dependencies, such as JogAmp JOGL, Harfbuzz font engine, Java Advanced Imaging JAI, please refer to Product Documentation.

Other supported file formats

You can perform compare operation for other file formats:


Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2023. All Rights Reserved.