zoukankan      html  css  js  c++  java
  • C#检测两个文件内容是否相同

    不知道为什么对Excel 2010 xlsx后缀的文件没有效果,求解!

    对其他文件有效,如.txt,.csv

     1 using System;
     2 using System.Security.Cryptography;
     3 using System.IO;
     4 
     5 namespace CheckFile
     6 {
     7     class Program
     8     {
     9         static void Main(string[] args)
    10         {
    11             string filePath1 = @"D:/1.txt";
    12             string filePath2 = @"D:/2.txt";
    13             bool result = CheckFile(filePath1, filePath2);
    14             Console.WriteLine(result.ToString());
    15             Console.ReadKey();
    16 
    17         }
    18         /// <summary>
    19         /// Check File
    20         /// </summary>
    21         /// <param name="filePath1"></param>
    22         /// <param name="filePath2"></param>
    23         /// <returns></returns>
    24         public static bool CheckFile(string filePath1, string filePath2)
    25         {
    26             using (HashAlgorithm hash = HashAlgorithm.Create())
    27             {
    28                 using (FileStream file1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read)
    29                     , file2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
    30                 {
    31                     byte[] hashByte1 = hash.ComputeHash(file1);
    32                     byte[] hashByte2 = hash.ComputeHash(file2);
    33                     string str1 = BitConverter.ToString(hashByte1);
    34                     string str2 = BitConverter.ToString(hashByte2);
    35                     return (str1 == str2);
    36                 }
    37             }
    38         }
    39     }
    40 }
  • 相关阅读:
    hdu1430 魔板(康拓展开 bfs预处理)
    网络流EdmondsKarp算法模板理解
    poj3020 建信号塔(匈牙利算法 最小覆盖边集)
    bzoj 2465 小球
    bzoj 1822 冷冻波
    bzoj 1040 骑士
    Codeforces Round #460 (Div. 2)
    bzoj 1072 排列perm
    Codeforces Round #459 (Div. 2)
    bzoj 1087 互不侵犯King
  • 原文地址:https://www.cnblogs.com/minotmin/p/3492776.html
Copyright © 2011-2022 走看看