我想我们很多时候想比较一个文件里面是否有改动,比如一个dll库是新加了一个方法或修改了其中的方法实现,不能通过可视化的工具来比较的时候,可以用这个小工具来比较, 以下是比较文件的代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; namespace FilesCompare
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please type the first file.");
string firstFilePath = Console.ReadLine(); Console.WriteLine("Please type the second file.");
string secondFilePath = Console.ReadLine(); bool isEqual = CompareFiles(firstFilePath, secondFilePath);
Console.WriteLine(isEqual ? "equal" : " Not equal"); Console.Read();
} public static bool CompareFiles(string targetFile, string updatedFile)
{
FileInfo targetFileInfo = new FileInfo(targetFile);
FileInfo updatedFileInfo = new FileInfo(updatedFile); if (targetFileInfo.Length != updatedFileInfo.Length)
{
return false;
} using (FileStream targetStream = File.OpenRead(targetFile))
{
using (FileStream updatedStream = File.OpenRead(updatedFile))
{
if (targetStream.Length != updatedStream.Length)
{
return false;
} // Using a larger buffer than the default buffer of 4 * 1024 used by FileStream.ReadByte improves performance.
// The buffer size is based on user feedback. Based on performance results, a better buffer size may be determined.
byte[] targetBuffer = new byte[ * ];
byte[] updatedBuffer = new byte[ * ];
int targetReadLength;
int updatedReadLength;
do
{
targetReadLength = targetStream.Read(targetBuffer, , targetBuffer.Length);
updatedReadLength = updatedStream.Read(updatedBuffer, , updatedBuffer.Length); if (targetReadLength != updatedReadLength)
{
return false;
} for (int i = ; i < targetReadLength; ++i)
{
if (targetBuffer[i] != updatedBuffer[i])
{
return false;
}
} } while ( < targetReadLength);
}
} return true;
} }
}

c#文件比较Code的更多相关文章

  1. 解决npm : 无法加载文件 D:\Code\renren-fast-vue\node_modules\.bin\npm.ps1,因为在......

    解决这个问题: 看看错误信息: npm : 无法加载文件 D:\DevPath\nodejs\npm.ps1,因为在此系统上禁止运行脚本.有关详细信息,请参阅 https:/go.microsoft. ...

  2. 在visual studio code和visual studio中编写TypeScript文件自动生成JavaScript文件

    注:此处的自动生成都为保存ts文件时自动生成js文件 VS CODE 只需要在TypeScript的终端控制台中输入如下命令即可,并注意需要将其中的*换成对应的文件名,此处的*似乎不能作为通用匹配. ...

  3. Visual Studio Code 配置指南

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器.在我看来它是「一款完美的编辑器」. 本文是有关 VS Code 的特性介绍与配置指 ...

  4. Inno Setup 如何读写文件

    软件安装的实质就是拷贝,对于简单的打包当然不需要考虑修改某(配置)文件.通过inno修改文件的目的在于把安装时相关信息写入文件中,提供其它应用的读取,而这些信息也只能在安装时才能确定,比如安装用户选择 ...

  5. php课程---文件操作及文件上传的代码总结

    php里面文件包含目录和文件两种 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  6. PHP文件包含漏洞剖析

    一. 什么才是”远程文件包含漏洞”?回答是:服务器通过php的特性(函数)去包含任意文件时,由于要包含的这个文件来源过滤不严,从而可以去包含一个恶意文件,而我们可以构造这个恶意文件来达到邪恶的目的. ...

  7. PHP代码为什么不能直接保存HTML文件——&gt;PHP生成静态页面教程

    1.server会依据文件的后缀名去进行解析,假设是HTML文件则server不会进行语法解析.而是直接输出到浏览器. 2.假设一个页面中所有都是HTML代码而没有须要解析的PHP语法,则没有必要保存 ...

  8. java之文件夹

    1.文件夹的创建 code: package com.test; import java.io.File; public class Folder_test { public static void ...

  9. 使用和制作patch文件

    使用和制作patch文件 发表时间: 2007-2-13 20:57    作者: superuser    来源: 迷茫人 字体: 小 中 大 | 打印 原文http://www.linuxsir. ...

随机推荐

  1. ios 错误纪录

    .self.出不来的原因 Member reference type 'struct objc_class *' is a pointer; maybe you meant to use '-> ...

  2. Faiss教程:索引(2)

    索引的I/O与复制 所有的函数都是深复制,我们不需要关心对象关系. I/O函数: write_index(index, "large.index"): 写索引到文件 Index * ...

  3. Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this

    最近使用新版本的mysql,执行语句的时候报错.网上找了一下,解决方法如下: vim /etc/mysql/conf.d/mysql.cnf [mysqld] sql_mode=STRICT_TRAN ...

  4. Centos 7.0 Firewall-cmd 使用方式

    开启端口命令 输入firewall-cmd --query-port=6379/tcp,如果返回结果为no,那么证明6379端口确实没有开启.输入firewall-cmd --add-port=637 ...

  5. linux 发送Post请求 json格式

    curl -H "Content-type: application/json" -X POST -d '{"text":"总体来说很不错,环境挺好的 ...

  6. andorid 计算器

    avtivity_main.xml <?xml version="1.0" encoding="utf-8"?> <GridLayout xm ...

  7. 反射中,Class.forName 和 classloader 的区别

    https://blog.csdn.net/qq_27093465/article/details/52262340 java中class.forName()和classLoader都可用来对类进行加 ...

  8. Django 访问admin提示ViewDoesNotExist at /admin/

    ViewDoesNotExist at /admin/ Could not import django.views.generic.simple.redirect_to. Parent module ...

  9. html里<div> <br /> <p>三者区别

    一.语法不同   -   TOP div和p是成对组合闭合标签:<br />是单一的闭合标签. 以<div>开始,</div>结束:以<p>开始,< ...

  10. [Hbase]Hbase章1 Hbase框架及基本概念

    Hbase框架介绍 HBase是一个分布式的.面向列的开源数据库. 不同点: l  和一般的关系数据库不同,hbase是一个适合于非结构化数据存储的数据库. l  Hbase是基于列而不是基于行的模式 ...