1. 程式人生 > >判斷兩個文件是否相同

判斷兩個文件是否相同

[] 得到 數組 creat files 算法 else byte 文本

using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file1 = new FileStream(FilePath1, FileMode.Open), file2 = new FileStream(FilePath2, FileMode.Open))
{
byte[] hashByte1 = hash.ComputeHash(file1);//哈希算法根據文本得到哈希碼的字節數組
byte[] hashByte2 = hash.ComputeHash(file2);
string str1 = BitConverter.ToString(hashByte1);//將字節數組裝換為字符串
string str2 = BitConverter.ToString(hashByte2);
if (str1 == str2)
{

//write

}
else
{

//write

}
}
}

判斷兩個文件是否相同