Java 12 brought some useful additions and comparing two files using a newly added method ‘Mismatch()’ is one of them. In this post, we will learn “How to use Files.mismatch() method introduced in Java 12?”. 

Here, we are going to learn the following things:

  1. What is Files.mismatch() method?
  2. How to use it?

Compare files with Files.mismatch() in Java 12...!!! Share on X

Let’s Begin,

1. What is Files.mismatch() method?

This method returns the position of the first mismatch or -1L if there is no mismatch. 

Files_Mismatch_Java12_Signature

2. How to use it?

Let’s take an example where we have a few temp files. First, we are comparing the files which are identical, and later comparing the unidentical ones using ‘mismatch()’ method. 

Output:

Compare files with Files.mismatch() in Java 12...!!! Share on X

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    http://Techndeck.com deepak.rkgit@gmail.com Verma Deepak