当前位置: 移动技术网 > IT编程>开发语言>.net > 判断两个文件是否是同一个文件

判断两个文件是否是同一个文件

2018年10月14日  | 移动技术网IT编程  | 我要评论

可疑的英雄,幸福婚嫁网,张家界汽车站

通过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);
        }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网