To avoid the saving stream as a file, GroupDocs.Comparison allows you to work with file streams directly.
The following code snippet shows how to load a file from a stream:
'use strict';// Load Java bridge and import FileInputStream for reading files
constgroupdocs=require('@groupdocs/groupdocs.comparison');constjava=require('java');constInputStream=java.import('java.io.FileInputStream');// Create input streams for source and target documents
constsourceStream=newInputStream('sample-files/source.docx');// source document
consttargetStream=newInputStream('sample-files/target.docx');// target document
// Initialize comparer with the source document stream
constcomparer=newgroupdocs.Comparer(sourceStream);// Add the target document to the comparison set
comparer.add(targetStream);// Execute comparison and save result to a new file
comparer.compare('result.docx');// Terminate the process with a success exit code
process.exit(0);
This example demonstrates how to compare documents using Java input streams instead of file paths. It creates InputStream objects for both the source and target documents using Java’s FileInputStream class, initializes the Comparer with the source stream, adds the target stream using add(), and performs the comparison. This approach is useful when working with documents stored in memory or when you want to avoid direct file system access.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.