[英]Java how to read a txt file and make each line it's own string array
[英]Compare each line in a .txt file to a array String in Java
public static boolean checkChecksum(String filePath, String checksumPath) throws Exception{
File file = new File(filePath);
File checksum1 = new File(checksumPath);
try {
ZipFile zipFile = new ZipFile(file);
Enumeration e = zipFile.entries();
while(e.hasMoreElements()) {
ZipEntry entry = (ZipEntry)e.nextElement();
String entryName = entry.getName();
long crc = entry.getCrc();
String current_crc = crc+"";
}
zipFile.close();
return true;
}
catch (IOException ioe) {
log.debug("Zip file may be corrupted");
System.out.println("Error opening zip file" + ioe);
return false;
}
}
我想將checksum1
文件中的每一行與我從file.zip
獲得的每個字符串值current_crc
進行比較。
我怎么能做到? 以及在從其他 PC 移動到另一台 PC 后,我是否有其他解決方案來檢查 zip 文件中的文件。
從其他 PC 移動到另一台 PC 后,我是否有其他解決方案來檢查 zip 文件中的文件。
通常我們使用 hash 校驗和來檢查文件的完整性——它們效率更高,幾乎同樣可靠。 例子:
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(data);
此代碼從輸入字節[](數據)生成一個小字節[]。 為了檢查 zip 文件,從原始 zip 創建 hash 並檢查復制的 zip 的 Z08040FC5772839434 是否相同就足夠了。 您可以使用 Arrays.equals() 方法,也可以將字節 arrays 轉換為 Base64 字符串以便於閱讀。
有趣的事實:兩個 256 位哈希匹配的機會大致相當於在第一次嘗試中正確猜測 49 個字符長的字母數字密碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.