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 }
  • 相关阅读:
    wait与sleep区别?
    oracle死锁查询
    atomic 原子操作的类
    买票问题
    0001.第一个多线程demo--分批处理数据
    01: JavaScript实例
    01: 运维工作梳理
    04: 使用BeautifulSoup封装的xss过滤模块
    04: 打开tornado源码剖析处理过程
    03: 自定义异步非阻塞tornado框架
  • 原文地址:https://www.cnblogs.com/minotmin/p/3492776.html
Copyright © 2011-2022 走看看