Pages

Saturday, May 29, 2010

比较两个大文件是否相同

可以计算它们的MD5,看MD5值是否相同
//Code for calculate MD5
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography; namespace MD5
{
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
FileStream fs = new FileStream(@"F:\tiny_images.bin", FileMode.Open); //The file path
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(fs);
fs.Close();
foreach (byte hex in hash)
sb.Append(hex.ToString("x2"));
string md5sum = sb.ToString();
}
}
}

No comments:

 

Locations of visitors to this page

Web Counters
Cheap Hotel Rates