我想我们很多时候想比较一个文件里面是否有改动,比如一个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. Server2003+IIS6+TP-Link+花生壳配置

    Server2003+IIS6+TP-Link+花生壳配置外网一共分四步: 固定Server2003电脑的局域网IP地址. 设置IIS网站中的TCP端口. 在TP-Link中设置转发规则. 申请花生壳 ...

  2. redis创建集群——[ERR] Sorry, can't connect to node 192.168.X.X

    创建集群或者连接时会出现错误:只能用127.0.0.1创建 这是需要修改redis.conf 把bind注释掉 protected-mode no 有些旧版本注释requirepass 技术交流群:8 ...

  3. stark组件开发之自动生成URL

    app01\model.py from django.db import models # Create your models here. class Depart(models.Model): i ...

  4. WebAPI支持Session

    1.在App_Start/WebApiConfig.cs中建立建立HttpControllerHandler和HttpControllerRouteHandler 并覆写它: public class ...

  5. oracle 分页 where 三层

    查询[start,start+limit],包含start,包含start+limit,如start=21,limit=10结果就是21到30,包含21和30SELECT * FROM (SELECT ...

  6. Android开发之使用GridView+仿微信图片上传功能(附源代码)

    前言:如果转载文章请声明转载自:https://i.cnblogs.com/EditPosts.aspx?postid=7419021  .另外针对有些网站转载本人的文章结果源码链接不对的问题,本人在 ...

  7. (转)JavaScript的压缩

    JavaScript的压缩 (转自)http://blog.csdn.net/ybygjy/article/details/6995435 简述 如果非常着急,这块可以跳过直接从约束条件开始也行. J ...

  8. Java 7.35 游戏:猜字游戏(C++&Java)

    Ps: 有人可能好奇我为什么大费周章的去写主函数,而不直接把所有操作放在类中,Why?类就好比骨干(存放核心的数据和功能),最好提供接口, 避免了类中的输入输出,当然,这也不是绝对的. C++: #i ...

  9. 20172306 《Java程序设计与数据结构》第七周学习总结

    20172306<Java程序设计>第七周学习总结 教材学习内容总结 这一章的标题是继承.主要学习了有关继承的相关知识.其中在这五节中,我学到了以下几点: 1.继承主要表达的是" ...

  10. Eloquent Attach/Detach/Sync Fires Any Event

    eloquent-attach-detach-sync-fires-any-event I have a laravel project, and I need to make some calcul ...