How to compare two or more files in Java or Kotlin

Document comparison is one of the most common requirements for today’s world. Whether it is to compare word files, compare excel files, presentations, PDF documents or even compare text files or any other document format, accuracy is the key factor while comparing.

This article will give you the idea, how GroupDocs.Comparison facilitates programmers to compare any two or more documents in many ways. On-Premise APIs of GroupDocs.Comparison are currently available for .NET and Java, however, this article is inclined towards Java or Kotlin developers.

Compare Excel, Word files or any other documents in Java or Kotlin

GroupDocs.Comparison for Java allows developers to compare two documents (in fact more than 2). The resulting document shows the changes between the two files in comparison. Below shown code how you can compare two excel files in just 3 lines of code in Java or Kotlin.

  • Instantiate the Comparer object with the source document path or stream.
  • Call add method to specify the target(s) document path(s).
  • Call the compare method to run comparison process.

Comparing documents by paths
Java
Kotlin

Comparing excel spreadsheets or Microsoft Word documents are just among the subset of documents formats that are supported by the Java API of GroupDocs.Comparison. Below is the list of supported formats. You can visit the documentation to stay updated.

Document TypeFormats
Word ProcessingDOC, DOCX, DOCM, DOT, DOTX, DOTM, RTF, TXT
SpreadsheetsXLS, XLSX, XLSM, XLT, XLTM, XLSB, XLSM, CSV
PresentationsPPT, PPTX, PPS, PPSX, POT, POTX
OpenDocumentODT, ODP, OTP, ODS, OTT
PortablePDF
MicrosoftVisio Drawings VSD, VSDX, VSS, VST, VDX
Note TakingONE
WebHTM, HTML, MHT, MHTML
eBooksMOBI
ImagesBMP, GIF, JPG, JPEG, PNG, DICOM, DJVU, DWG, DXF
EmailsEML, EMLX, MSG

Compare two or more Spreadsheets or OneNote Documents in Java or Kotlin

After the release of GroupDocs.Comparison for Java 20.4, the API now supports:

  • Comparison of more than two Microsoft Excel and OpenOffice spreadsheets (XLS, XLSX, ODS, CSV, …)
  • Compare multiple Microsoft OneNote documents

The API already supports the comparison of multiple files for various document formats. Following code snippet shows how easy, multiple excel files can be compared in Java or Kotlin


Comparing multiple Excel documents
Java
Kotlin

Compare Documents from stream in Java or Kotlin

As a programmer, you are not only allowed to compare documents that are available on local disk, but also you can compare documents from streams.

  • Just create the Comparer object with the source document stream.
  • Add all target documents to compare using the add method of Comparer object.
  • Call the compare method to write result document into output stream.

Comparing multiple Excel documents from streams
Java
Kotlin

Compare Password Protected Word Documents / Excel Spreadsheet in Java or Kotlin

Password protection is common in the official documentation. Using the document comparison Java API, allows its users/developers to compare password-protected documents.

Just a little change in the code of comparing documents that are not password-protected. While loading the document, use LoadOptions to specify the document password. Below is the sample comparison code for your assistance.


Comparing multiple password-protected Excel documents from streams
Java
Kotlin

Comparison of Documents with Specific Settings

One step ahead of just comparing, using the code similar to the mentioned below, you can compare multiple documents with your customized comparison settings.

CompareOptions provides you the opportunity to specify your comparison options like font styling for detected changes etc.


Comparing multiple documents with specific style settings
Java
Kotlin

Compare Programming Language Files in Java or Kotlin

GroupDocs continuously increasing the support to compare more file formats. After the release v 20.4, you can now also compare JSON files using Java API. Following are the programming language file formats that are recently added to the supported document formats list:

LanguageFile format
ActionScriptObjective C/C++
AssemblerPerl
C-BasedPHP
CSharpPython
GroovyRuby
JavaScriptScala
JavaShell/Batch Script, Log, Diff, Config, LESS
JSONSQL

You can build your own application using the above-highlighted features. We will be delighted if you contact us on the forum to discuss, solving a problem, or share your feedback.

See also