import java.nio.file.Files; import java.nio.file.Paths; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { byte[] fileBytes = Files.readAllBytes(Paths.get("/path/to/file")); System.out.println(Arrays.toString(fileBytes)); } }
import java.nio.file.Files; import java.nio.file.Paths; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { byte[] file1Bytes = Files.readAllBytes(Paths.get("/path/to/file1")); byte[] file2Bytes = Files.readAllBytes(Paths.get("/path/to/file2")); if (Arrays.equals(file1Bytes, file2Bytes)) { System.out.println("The contents of the files are equal."); } else { System.out.println("The contents of the files are not equal."); } } }These examples use the java.nio.file.Files class, which is in the java.base module.