判断两个文件是否是同一个文件
程序员文章站
2022-09-24 10:35:25
通过System.Security.Cryptography.HashAlgorithm 哈希算法获取文件的哈希值比较判断 ......
通过system.security.cryptography.hashalgorithm 哈希算法获取文件的哈希值比较判断
public static bool comparefile(string filepath1, string filepath2) { //计算第一个文件的哈希值 hashalgorithm hash = hashalgorithm.create(); var stream_1 = new system.io.filestream(filepath1, system.io.filemode.open); byte[] hashbyte_1 = hash.computehash(stream_1); stream_1.close(); //计算第二个文件的哈希值 var stream_2 = new system.io.filestream(filepath2, system.io.filemode.open); byte[] hashbyte_2 = hash.computehash(stream_2); stream_2.close(); return bitconverter.tostring(hashbyte_1) == bitconverter.tostring(hashbyte_2); }
上一篇: 规避安全隐患 笔记本电池购买与使用攻略
下一篇: 笔记本电池A,B,C,D之电芯解惑