guohu

判断二个文件是否相同,通过判断文件的哈希值是否一致。

        var hash = System.Security.Cryptography.HashAlgorithm.Create();
        string fileName = "Z:\\Tools\\Common\\winx64_12102_database_1of2.zip";
        var fileStream = System.IO.File.Open(fileName, System.IO.FileMode.Open);
        var bytes1 = hash.ComputeHash(fileStream);
        fileStream.Close();

        fileName = "Z:\\Tools\\Common\\winx64_12102_database_1of2.zip";
        fileStream = System.IO.File.Open(fileName, System.IO.FileMode.Open);
        var bytes2 = hash.ComputeHash(fileStream);
        fileStream.Close();

        if (BitConverter.ToString(bytes1) == BitConverter.ToString(bytes2))
        {
            Response.Write("相同文件");
        }
        else
        {
            Response.Write("不同文件");
        } 

  

分类:

技术点:

相关文章:

  • 2021-07-24
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-03-31
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案