Skip to content

Instantly share code, notes, and snippets.

@nowshad-hasan
Created October 9, 2021 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowshad-hasan/8cddc4006573605de8de855dec8a4e24 to your computer and use it in GitHub Desktop.
Save nowshad-hasan/8cddc4006573605de8de855dec8a4e24 to your computer and use it in GitHub Desktop.
public class FileMismatchExample {
/*
Here, hello1 and hello3 have same content, hello2 has different content.
*/
public static void main(String[] args) {
Path path1 = Path.of("hello1.txt");
Path path2 = Path.of("hello2.txt");
Path path3 = Path.of("hello3.txt");
try {
System.out.println(Files.mismatch(path1, path1)); // -1, as same file comparison
System.out.println(Files.mismatch(path1, path2)); // 13, different files, different content
System.out.println(Files.mismatch(path1, path3)); // -1, as same content
System.out.println(Files.mismatch(path2, path3)); // 13, different files, different content
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment