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 }
  • 相关阅读:
    解决js跨域
    判断js对象类型
    闭包的理解
    this关键字
    js的数据类型
    多线程
    JavaEE之动态页面技术(JSP/EL/JSTL)
    JavaEE之HttpServletResponse
    JavaEE之HttpServletRequest
    JavaEE之会话技术Cookie&Session
  • 原文地址:https://www.cnblogs.com/minotmin/p/3492776.html
Copyright © 2011-2022 走看看