Class FilesMismatchExamples

java.lang.Object
net.jrodolfo.java_evolution.java12.FilesMismatchExamples

public class FilesMismatchExamples extends Object
Demonstrates Files.mismatch(Path, Path), introduced in Java 12.

Before Java 12, finding the first byte where two files differed required manual byte comparison or an external tool. That was too much plumbing for a common diagnostic and testing task.

Files.mismatch solves this by returning -1 when files match or the first differing byte position when they do not.

  • Constructor Details

    • FilesMismatchExamples

      public FilesMismatchExamples()
  • Method Details

    • firstMismatchPosition

      public long firstMismatchPosition(Path first, Path second) throws IOException
      Finds the first byte position where two files differ.
      Parameters:
      first - the first file
      second - the second file
      Returns:
      -1 when files match, otherwise the first mismatch position
      Throws:
      IOException - when file access fails