How to compare two or more files in Java or Kotlin
How to compare two or more files in Java or Kotlin
Leave feedback
On this page
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
JavaKotlin
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.
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
JavaKotlin
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
JavaKotlin
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
JavaKotlin
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
JavaKotlin
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:
Language
File format
ActionScript
Objective C/C++
Assembler
Perl
C-Based
PHP
CSharp
Python
Groovy
Ruby
JavaScript
Scala
Java
Shell/Batch Script, Log, Diff, Config, LESS
JSON
SQL
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.