如何使用FileInputStream在Java中比较字节与字节 [英] How to compare byte to byte in Java using FileInputStream
本文介绍了如何使用FileInputStream在Java中比较字节与字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以编写伪代码来比较Java中的字节与字节.我了解我们使用read()读取字节到字节.但是我们如何进行比较呢?
can anyone write pseudocode to compare byte to byte in Java. I understand that we use read() to read byte to byte. but how do we do the comparison?
推荐答案
试一下...
static boolean areFilesEqual (Path file1, Path file2) {
byte[] f1 = Files.readAllBytes(file1);
byte[] f2 = Files.readAllBytes(file2);
if (f1.length != f2.length)
return false;
else {
for (int i = 0; i < f1.length; i++) {
if (f1[i] != f2[i])
return false;
}
return true;
}
}
这篇关于如何使用FileInputStream在Java中比较字节与字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文