C#二进制文件比较程序

c#程序中调用Oracle存储过程上传二进制文件 最新做一个新的项目,用到了微软的Enterprise Library库,该库支持SQL和Oracle的统一访问,因此不能用SqlConnectionClient或OracleConnectionClient中自定义的数据类型,只能使用通用的DbType,但是其中的二进制内容只能容纳8K,这对于上传文件或者图片来说,肯定是不够用的,通过仔细研究Oracle的存储过程,自己写了一个无限上传二进制内容的 阅读详情

转:http://www.cnblogs.com/hbhbice/archive/2010/06/30/1768477.html

 

 

 

下面是CompareFile.cs

using System;
 using System.Collections.Generic;
 using System.Text;
 using System.IO;
 using System.Windows.Forms;
 using System.Data;
 
 namespace CompareFile
 {
     public  class FileCompare
     {
         private FileStream fs1, fs2;
         private DataTable _DiffTab1,_DiffTab2;
 
         public DataTable DiffTab1
         {
             get {
                 return _DiffTab1;
             }
         }
 
         public DataTable DiffTab2
         {
             get
             {
                 return _DiffTab2;
             }
         }
 
         public FileCompare(FileStream fs1, FileStream fs2)
         {
             this.fs1 = fs1;
             this.fs2 = fs2;
         }
 
         public void CompareAllFile()
         {
             if (fs1 .Length !=fs2.Length )
             {
                 if (MessageBox.Show("两文件长度不等\r\n文件1长:" + fs1.Length.ToString() + "\r\n文件2长:" + fs2.Length.ToString() + "\r\n是否继续比较?", "文件比较结果") == DialogResult.Cancel )
                 {
                     return;
                 }
             }
             BinaryReader br1 = new BinaryReader (fs1 );
             BinaryReader br2 = new BinaryReader (fs2);
             long min = fs1.Length >= fs2.Length ? fs2.Length : fs1.Length;
             for (long i = 0; i <min   ; i++)
             {
                 if ( br1 .ReadByte ()!=br2 .ReadByte ())
                 {
                     if (MessageBox.Show("从0起,第" + (br1.BaseStream.Position - 1).ToString() + "个字节不匹配" + "是否继续搜寻?", "文件比较",MessageBoxButtons.OKCancel) == DialogResult.OK)
                     {
 
                     }
                     else 
                     {
                         br1.BaseStream.Seek((br1.BaseStream.Position / 50) * 50, 0);
                         br2.BaseStream.Seek((br1.BaseStream.Position / 50) * 50, 0);
                         if (br1 .BaseStream .Length - br1 .BaseStream .Position >50&&br2 .BaseStream .Length - br2 .BaseStream .Position >50)
                         {
                             _DiffTab1 = new DataTable();
                             _DiffTab2 = new DataTable();
                             DataColumn dc1 = new DataColumn("位置");
                             DataColumn dc2 = new DataColumn("数值");
                             DataColumn dc3 = new DataColumn("位置");
                             DataColumn dc4 = new DataColumn("数值");
                             _DiffTab1.Columns.Add(dc1);
                             _DiffTab1.Columns.Add(dc2);
                             _DiffTab2.Columns.Add(dc3);
                             _DiffTab2.Columns.Add(dc4);
                             for (int j = 0; j < 50; j++)
                             {
                                 DataRow dr1 = _DiffTab1.NewRow();
                                 dr1[0] = br1.BaseStream.Position;
                                 dr1[1] = br1.ReadByte();
                                 DiffTab1.Rows.Add(dr1);
                                 DataRow dr2 = _DiffTab2.NewRow();
                                 dr2[0] = br2.BaseStream.Position;
                                 dr2[1] = br2.ReadByte();
                                 DiffTab2.Rows.Add(dr2);
                             }
                         }
                         return;                                
                     }
 
 
                 }
                 if (fs1.Position == min )
                 {
                     MessageBox.Show("到达两文件中较小文件的尾部");
                 }
             }
                 
 
         }
     }
 }


 

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CompareFile
{
    public partial class Form1 : Form
    {
        FileStream fs1;
        FileStream fs2;

        public Form1()
        {
            InitializeComponent();
        }

        private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1 .ShowDialog ()== DialogResult .OK )
            {
                fs1 = (FileStream )openFileDialog1.OpenFile();
            }
        }

        private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog ()== DialogResult .OK )
            {
                fs2 = (FileStream )openFileDialog1.OpenFile();
            }
        }

        private void 自定义CToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (fs1 != null && fs2 != null)
            {
                CompareFile.FileCompare fc = new CompareFile.FileCompare(fs1, fs2);
                fc.CompareAllFile();
                dataGridView1.DataSource = fc.DiffTab1;
                dataGridView2.DataSource = fc.DiffTab2;
            }
            else
            {
                MessageBox.Show ("请先将两个文件打开,然后再进行比较!");
            }

        }

        private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fs1.Close();
            fs2.Close();

        }

    }
}
 


 

Form1.Designer.cs(如果界面方面不清楚,参考以下代码。)

namespace CompareFile
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.新建NToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.打开OToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.保存SToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
            this.另存为AToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.打印PToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.打印预览VToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.退出XToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.编辑EToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.撤消UToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.重复RToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
            this.剪切TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.复制CToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.粘贴PToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
            this.全选AToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.工具TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.自定义CToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.选项OToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.帮助HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.内容CToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.索引IToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.搜索SToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
            this.关于AToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.splitContainer1 = new System.Windows.Forms.SplitContainer();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.dataGridView2 = new System.Windows.Forms.DataGridView();
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
            this.menuStrip1.SuspendLayout();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.文件FToolStripMenuItem,
            this.编辑EToolStripMenuItem,
            this.工具TToolStripMenuItem,
            this.帮助HToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(676, 24);
            this.menuStrip1.TabIndex = 0;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // 文件FToolStripMenuItem
            // 
            this.文件FToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.新建NToolStripMenuItem,
            this.打开OToolStripMenuItem,
            this.保存SToolStripMenuItem,
            this.toolStripSeparator,
            this.另存为AToolStripMenuItem,
            this.toolStripSeparator1,
            this.打印PToolStripMenuItem,
            this.打印预览VToolStripMenuItem,
            this.toolStripSeparator2,
            this.退出XToolStripMenuItem});
            this.文件FToolStripMenuItem.Name = "文件FToolStripMenuItem";
            this.文件FToolStripMenuItem.Size = new System.Drawing.Size(59, 20);
            this.文件FToolStripMenuItem.Text = "文件(&F)";
            // 
            // 新建NToolStripMenuItem
            // 
            this.新建NToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("新建NToolStripMenuItem.Image")));
            this.新建NToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.新建NToolStripMenuItem.Name = "新建NToolStripMenuItem";
            this.新建NToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
            this.新建NToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.新建NToolStripMenuItem.Text = "新建(&N)";
            // 
            // 打开OToolStripMenuItem
            // 
            this.打开OToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("打开OToolStripMenuItem.Image")));
            this.打开OToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.打开OToolStripMenuItem.Name = "打开OToolStripMenuItem";
            this.打开OToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
            this.打开OToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.打开OToolStripMenuItem.Text = "打开文件1(&O)";
            this.打开OToolStripMenuItem.Click += new System.EventHandler(this.打开OToolStripMenuItem_Click);
            // 
            // 保存SToolStripMenuItem
            // 
            this.保存SToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.保存SToolStripMenuItem.Name = "保存SToolStripMenuItem";
            this.保存SToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
            this.保存SToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.保存SToolStripMenuItem.Text = "打开文件2(&S)";
            this.保存SToolStripMenuItem.Click += new System.EventHandler(this.保存SToolStripMenuItem_Click);
            // 
            // toolStripSeparator
            // 
            this.toolStripSeparator.Name = "toolStripSeparator";
            this.toolStripSeparator.Size = new System.Drawing.Size(187, 6);
            // 
            // 另存为AToolStripMenuItem
            // 
            this.另存为AToolStripMenuItem.Name = "另存为AToolStripMenuItem";
            this.另存为AToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.另存为AToolStripMenuItem.Text = "关闭两文件(&A)";
            this.另存为AToolStripMenuItem.Click += new System.EventHandler(this.另存为AToolStripMenuItem_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(187, 6);
            // 
            // 打印PToolStripMenuItem
            // 
            this.打印PToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("打印PToolStripMenuItem.Image")));
            this.打印PToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.打印PToolStripMenuItem.Name = "打印PToolStripMenuItem";
            this.打印PToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P)));
            this.打印PToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.打印PToolStripMenuItem.Text = "打印(&P)";
            // 
            // 打印预览VToolStripMenuItem
            // 
            this.打印预览VToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("打印预览VToolStripMenuItem.Image")));
            this.打印预览VToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.打印预览VToolStripMenuItem.Name = "打印预览VToolStripMenuItem";
            this.打印预览VToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.打印预览VToolStripMenuItem.Text = "打印预览(&V)";
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new System.Drawing.Size(187, 6);
            // 
            // 退出XToolStripMenuItem
            // 
            this.退出XToolStripMenuItem.Name = "退出XToolStripMenuItem";
            this.退出XToolStripMenuItem.Size = new System.Drawing.Size(190, 22);
            this.退出XToolStripMenuItem.Text = "退出(&X)";
            // 
            // 编辑EToolStripMenuItem
            // 
            this.编辑EToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.撤消UToolStripMenuItem,
            this.重复RToolStripMenuItem,
            this.toolStripSeparator3,
            this.剪切TToolStripMenuItem,
            this.复制CToolStripMenuItem,
            this.粘贴PToolStripMenuItem,
            this.toolStripSeparator4,
            this.全选AToolStripMenuItem});
            this.编辑EToolStripMenuItem.Name = "编辑EToolStripMenuItem";
            this.编辑EToolStripMenuItem.Size = new System.Drawing.Size(60, 20);
            this.编辑EToolStripMenuItem.Text = "编辑(&E)";
            // 
            // 撤消UToolStripMenuItem
            // 
            this.撤消UToolStripMenuItem.Name = "撤消UToolStripMenuItem";
            this.撤消UToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Z)));
            this.撤消UToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.撤消UToolStripMenuItem.Text = "撤消(&U)";
            // 
            // 重复RToolStripMenuItem
            // 
            this.重复RToolStripMenuItem.Name = "重复RToolStripMenuItem";
            this.重复RToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Y)));
            this.重复RToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.重复RToolStripMenuItem.Text = "重复(&R)";
            // 
            // toolStripSeparator3
            // 
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            this.toolStripSeparator3.Size = new System.Drawing.Size(153, 6);
            // 
            // 剪切TToolStripMenuItem
            // 
            this.剪切TToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("剪切TToolStripMenuItem.Image")));
            this.剪切TToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.剪切TToolStripMenuItem.Name = "剪切TToolStripMenuItem";
            this.剪切TToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.X)));
            this.剪切TToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.剪切TToolStripMenuItem.Text = "剪切(&T)";
            // 
            // 复制CToolStripMenuItem
            // 
            this.复制CToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("复制CToolStripMenuItem.Image")));
            this.复制CToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.复制CToolStripMenuItem.Name = "复制CToolStripMenuItem";
            this.复制CToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
            this.复制CToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.复制CToolStripMenuItem.Text = "复制(&C)";
            // 
            // 粘贴PToolStripMenuItem
            // 
            this.粘贴PToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("粘贴PToolStripMenuItem.Image")));
            this.粘贴PToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.粘贴PToolStripMenuItem.Name = "粘贴PToolStripMenuItem";
            this.粘贴PToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V)));
            this.粘贴PToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.粘贴PToolStripMenuItem.Text = "粘贴(&P)";
            // 
            // toolStripSeparator4
            // 
            this.toolStripSeparator4.Name = "toolStripSeparator4";
            this.toolStripSeparator4.Size = new System.Drawing.Size(153, 6);
            // 
            // 全选AToolStripMenuItem
            // 
            this.全选AToolStripMenuItem.Name = "全选AToolStripMenuItem";
            this.全选AToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
            this.全选AToolStripMenuItem.Text = "全选(&A)";
            // 
            // 工具TToolStripMenuItem
            // 
            this.工具TToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.自定义CToolStripMenuItem,
            this.选项OToolStripMenuItem});
            this.工具TToolStripMenuItem.Name = "工具TToolStripMenuItem";
            this.工具TToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
            this.工具TToolStripMenuItem.Text = "工具(&T)";
            // 
            // 自定义CToolStripMenuItem
            // 
            this.自定义CToolStripMenuItem.Name = "自定义CToolStripMenuItem";
            this.自定义CToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
            this.自定义CToolStripMenuItem.Text = "比较(&C)";
            this.自定义CToolStripMenuItem.Click += new System.EventHandler(this.自定义CToolStripMenuItem_Click);
            // 
            // 选项OToolStripMenuItem
            // 
            this.选项OToolStripMenuItem.Name = "选项OToolStripMenuItem";
            this.选项OToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
            this.选项OToolStripMenuItem.Text = "选项(&O)";
            // 
            // 帮助HToolStripMenuItem
            // 
            this.帮助HToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.内容CToolStripMenuItem,
            this.索引IToolStripMenuItem,
            this.搜索SToolStripMenuItem,
            this.toolStripSeparator5,
            this.关于AToolStripMenuItem});
            this.帮助HToolStripMenuItem.Name = "帮助HToolStripMenuItem";
            this.帮助HToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
            this.帮助HToolStripMenuItem.Text = "帮助(&H)";
            // 
            // 内容CToolStripMenuItem
            // 
            this.内容CToolStripMenuItem.Name = "内容CToolStripMenuItem";
            this.内容CToolStripMenuItem.Size = new System.Drawing.Size(128, 22);
            this.内容CToolStripMenuItem.Text = "内容(&C)";
            // 
            // 索引IToolStripMenuItem
            // 
            this.索引IToolStripMenuItem.Name = "索引IToolStripMenuItem";
            this.索引IToolStripMenuItem.Size = new System.Drawing.Size(128, 22);
            this.索引IToolStripMenuItem.Text = "索引(&I)";
            // 
            // 搜索SToolStripMenuItem
            // 
            this.搜索SToolStripMenuItem.Name = "搜索SToolStripMenuItem";
            this.搜索SToolStripMenuItem.Size = new System.Drawing.Size(128, 22);
            this.搜索SToolStripMenuItem.Text = "搜索(&S)";
            // 
            // toolStripSeparator5
            // 
            this.toolStripSeparator5.Name = "toolStripSeparator5";
            this.toolStripSeparator5.Size = new System.Drawing.Size(125, 6);
            // 
            // 关于AToolStripMenuItem
            // 
            this.关于AToolStripMenuItem.Name = "关于AToolStripMenuItem";
            this.关于AToolStripMenuItem.Size = new System.Drawing.Size(128, 22);
            this.关于AToolStripMenuItem.Text = "关于(&A)...";
            // 
            // splitContainer1
            // 
            this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer1.Location = new System.Drawing.Point(0, 24);
            this.splitContainer1.Name = "splitContainer1";
            // 
            // splitContainer1.Panel1
            // 
            this.splitContainer1.Panel1.Controls.Add(this.dataGridView1);
            // 
            // splitContainer1.Panel2
            // 
            this.splitContainer1.Panel2.Controls.Add(this.dataGridView2);
            this.splitContainer1.Size = new System.Drawing.Size(676, 528);
            this.splitContainer1.SplitterDistance = 326;
            this.splitContainer1.TabIndex = 1;
            // 
            // dataGridView1
            // 
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Location = new System.Drawing.Point(0, 28);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.RowTemplate.Height = 23;
            this.dataGridView1.Size = new System.Drawing.Size(326, 500);
            this.dataGridView1.TabIndex = 0;
            // 
            // dataGridView2
            // 
            this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView2.Location = new System.Drawing.Point(0, 28);
            this.dataGridView2.Name = "dataGridView2";
            this.dataGridView2.RowTemplate.Height = 23;
            this.dataGridView2.Size = new System.Drawing.Size(346, 500);
            this.dataGridView2.TabIndex = 0;
            // 
            // openFileDialog1
            // 
            this.openFileDialog1.FileName = "openFileDialog1";
            // 
            // toolStrip1
            // 
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripButton1});
            this.toolStrip1.Location = new System.Drawing.Point(0, 24);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(676, 25);
            this.toolStrip1.TabIndex = 2;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // toolStripButton1
            // 
            this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
            this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton1.Name = "toolStripButton1";
            this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
            this.toolStripButton1.Text = "toolStripButton1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(676, 552);
            this.Controls.Add(this.toolStrip1);
            this.Controls.Add(this.splitContainer1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            this.splitContainer1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem 文件FToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 新建NToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 打开OToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator;
        private System.Windows.Forms.ToolStripMenuItem 保存SToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 另存为AToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
        private System.Windows.Forms.ToolStripMenuItem 打印PToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 打印预览VToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
        private System.Windows.Forms.ToolStripMenuItem 退出XToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 编辑EToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 撤消UToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 重复RToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
        private System.Windows.Forms.ToolStripMenuItem 剪切TToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 复制CToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 粘贴PToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
        private System.Windows.Forms.ToolStripMenuItem 全选AToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 工具TToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 自定义CToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 选项OToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 帮助HToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 内容CToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 索引IToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 搜索SToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
        private System.Windows.Forms.ToolStripMenuItem 关于AToolStripMenuItem;
        private System.Windows.Forms.SplitContainer splitContainer1;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataGridView dataGridView2;
        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.ToolStripButton toolStripButton1;

    }
}


 

C#中二进制文件读写操作实践指南 本文还有配套的精品资源,点击获取 简介:本文详细讲解了如何在C#中执行二进制文件的读写操作,涵盖了二进制文件的基本概念及其应用场景。通过示例代码,介绍了如何使用 FileStream 、 BinaryReader 和 BinaryWriter 等.NET类库进行数据的序列化和反序列化。同时提供了项目文件解析,帮助读者更好地理解这些操... 阅读详情

相关推荐

C#实现二进制文件读写操作详解

自定义对象的序列化和反序列化是将对象的状态信息转换为可以存储或传输的形式的过程,然后能够从这种形式重新构建原始对象。这一过程在编程中尤其重要,特别是在网络通信和数据持久化方面。本章将深入探讨序列化和反序列化的概念、方法以及如何在C#中使用.NET框架提供的工具来实现自定义对象的序列化和反序列化。序列化是将对象的当前状态转换为字节流的过程,这样就可以将其存储在磁盘上或通过网络发送。序列化的对象可以被反序列化回原始的类实例。

weixin_35756892的博客 719

文件对比工具c语言编程,C#编写的一个强大的目录文件比较

C#编写的一个强大的目录文件比较工具(DirComp)...........................................\About.cs...........................................\About.resx...........................................\AddEdit.cs................

weixin_36459164的博客 503

c# 动态比较两个文件是否相同(VS2008)

VS2008环境开发的c# 实例小程序,功能是动态比较两个文件是否相同,并没有给出详细的比对结果,只是说明文件相同或不相同,如源码爱好者编译截图,仅供C#初学者参考吧,帮助理解有关文件操作的知识技巧。

C#比较两个文件内容是否相同

今天看到项目的比较文件是先将所有字节读出来,然后逐一进行比较,想找找有没有可以优化的地方。在网上看了一下,有比较哈希码的,验证了一下,发现不管是文件开始就不相同,还是文件末尾才不相同,都比较耗时。 C#比较两个文本文件的内容是否相等 - 五点 - 博客园 (cnblogs.com) 测试文件大小:10000KB 一、比较哈希码 先将文件内容转成哈希码,然后进行比较。 public static bool CompareFile(string sourceFilePath, string

不文不武的禾文 4619

C#实现文件比较的功能,比较两个文件内容是否相同

C#实现文件比较的功能,即比较两个文件内容是否相同

C#.NET文件比较工具(含全部源代码)

.NET2.0 C#写的一个文件比较工具。可以比较文件和文件夹,支持拖放功能。操作方式效仿"Beyond Compare",界面用SyncFusion控件做的,淡蓝色界面。 (文件比较的算法是一个求公共最长字序列的算法,复杂度比较大,所以对大文件的处理效果不佳)

C# 文件比较差异

参考:https://www.cnblogs.com/vaevvaev/p/7115721.html 这里我就比较2个文件 使用了fc命令。 2个文件路径如下 path1,path2 static void Main(string[] args) { string path1 = @"C:\Users\Tyler\D...

weixin_30950237的博客 757

diff文件(夹)比对源码 c#

1.可以对文本文件精确查找。 2.不同区域会用不同颜色标注。(源码)

C#下的WPF应用程序:文件比对兼副本创建工具

1.关于本工具 这个工具是我用WPF写的一个测试工具,需求大致上是:有一个文件,它不定期会发生变化,现在要求监控这个文件,每当该文件改变,则创建一个该文件的副本。 在这个程序中,指定一个被监控文件的路径,设定一个拍摄快照的时间间隔,每次拍摄文件的快照后,根据设定比对当次快照与之前快照中...

418

C#文件比较,比较两个文件大小和内容是否一样

摘要:C#源码,文件操作,文件比较  C#文件比较,比较两个文件大小和内容是否一样,需要先引入using System.Drawing,将使用者所选取的文本文件的完整路径显示于TextBox1和 TextBox2文本框中,判断相同的文件是否被引用两次,检查文件大校如果两个文件的大小并不相同,则视为不相同,逐一比较两个文件的每一个字节,直到发现不相符或已到达文件尾端为止,从每一个文件读取一个字节,然后关闭文件,最后返回比较的结果。在这个时候,只有当两个文件的内容完全相同时,"file1byte" 才会等于 "file2byte"。

AUTOSAR—TM模块介绍及使用概要

根据所要测量的场景不同,有1us16bit、1us24bit、1us32bit、100us32bit四种类型可选;TM模块在服务层,提供一些基于时间的服务功能,如测量CPU和任务的负载,周期执行一些回调函数。2、对于需要在不同时间执行不同逻辑的周期任务中,可以搭建时间状态机:参考Tm用户手册;定时器复位、获取时间宽度、定时器转换、定时器同步、繁忙等待。偏移定时器实例的参考时间,直接将定时器数值进行偏移;以1us16bit定时器类型为例,讲几个常用函数。同步两个定时器,把源定时器时间值给到目的定时器。

qq_42479987的博客 616

c# 二进制文件编程实践

转载连接:http://blog.csdn.net/bcbobo21cn/article/details/69571692?locationNum=11&fps=1#t0 C读写二进制文件C二进制文件比较程序C Parsing 类实现的 PDF 文件分析器Windows下的开源二进制文件编辑器HexEdit C#读写二进制文件 http://www.cnblogs.com

newbie的博客 1447

SpaceX与NVIDIA星载AI计算载荷:从地面GPU到太空边缘计算的工程挑战

边缘计算将数据处理从云端推向网络边缘,通过在数据源头就近执行计算任务,减少延迟和带宽消耗。其核心原理是在资源受限的设备上部署轻量级算法,实现实时响应。这一技术价值在于赋能物联网、自动驾驶等场景,推动AI应用向物理世界更深层渗透。在航天领域,边缘计算演化为太空边缘计算,面临极端环境下的可靠性挑战。SpaceX与NVIDIA合作的星载AI计算载荷正是这一趋势的体现,它需要解决抗辐射设计、低功耗计算等难题,将高性能AI推理部署于近地轨道,实现卫星数据的实时处理与分析。

weixin_33682790的博客 460

自动更新程序源码下载(C#.Net)

自动更新程序源码下载(C#.Net)        由于微软提供的更新程序使用不方便,所以又写了此程序。此程序是本人一年前所写的一段程序,当时在开发一个CS版本报价系统,当时由于开发过程仓促,代码可能有点不是太规范此程序编译后只有一下AutoUpdate.exe文件与一个配置文件UpdateList.xml,主要通过本地程序与服务端程序文件的版本号来升级与更新本地程序文件。 U

足球中国的专栏 2740

NX二次开发入门必看:手把手教你搭建开发环境

想顺利开展nx二次开发,第一步就是配置好开发环境。本文详细讲解从安装准备到环境调试的完整流程,结合实际操作细节,帮你避开常见坑点,快速进入nx二次开发的实战阶段。

weixin_31569663的博客 1469

SAP-ABAP:SAP中如何查看系统表之间的关联关系?

在业务逻辑开发或者ALV开发过程中,我们通常要从系统中找出几个标准表之间的关联关系,有的是head与item,通过外键进行关联的关系。那么怎么去找到呢?以上就是具体如何产看系统表之间的关联关系的步骤,对于不同代码的业务顾问,也是必须要掌握的。

LinkStar的博客 2434

C#生成二进制文件

【代码】C#生成二进制文件。

江上清风山间明月的博客 1103

WSL 运行make提示/lib/modules/xxx/build: No such file or directory. Stop.错误解决办法

WSL运行make提示/lib//modules/xxx文件或目录不存在。 WSL2的内核是修改过的,无法使用 ubuntu上游的内核头文件和modules文件,因此,我们需要手动编译并安装一个版本。

weixin_45668903的博客 1万+

用C#读取二进制文件

当想到所有文件都转换为 XML时,确实是一件好事。但是,这并非事实。仍旧还有大量的文件格式不是XML,甚至也不是ASCII。二进制文件仍然在网络中传播,储存在磁盘上,在应用程序之间传递。相比之下,在处理这些问题方面,它们比文本文件显得更有效率些。在 C 和 C++ 中,读取二进制文件还是很容易的。除了一些开始符(carriage return)和结束符(line feed)的问题,每一个读到C

沉默之狼的专栏 4249

15、人工智能社会学:关系视角下的机器相遇

本文探讨了将人工智能视为社会主体的可能性,提出了一种关系视角下的人工智能社会学。通过结合卢西亚娜·帕里西、艾伦·图灵和乔治·赫伯特·米德的理论,强调不确定性在人工智能运行中的核心地位,并分析了人工智能如何通过与社会环境的互动催生新奇性,从而拓展社会学的研究范畴。文章还讨论了人工智能对社会结构和社会互动的影响,以及其作为社会主体所带来的理论和实践意义,为未来人工智能社会学的发展提供了方向。

pea55的博客 75

人像抠图 + OpenGL ES 还能这样玩?没想到吧(附带源码)

OpenGL ES 利用抠图算法实现人像留色。

字节流动 3万+

用 C# 读取二进制文件

当想到所有文件都转换为 XML时,确实是一件好事。但是,这并非事实。仍旧还有大量的文件格式不是XML,甚至也不是ASCII。二进制文件仍然在网络中传播,储存在磁盘上,在应用程序之间传递。相比之下,在处理这些问题方面,它们比文本文件显得更有效率些。在 C 和 C++ 中,读取二进制文件还是很容易的。除了一些开始符(carriage return)和结束符(line feed)的问题,每一个读到C

shaily读书学习 1036

[Dify] HTTP 请求节点总是调不通?先把请求头、参数、变量和返回 JSON 拆开查

这篇文章围绕 Dify HTTP 请求节点调不通、接口能通但流程不稳定、返回 JSON 后续节点读不到等问题展开,从 Method、URL、Header、Body、变量映射和返回字段提取几个角度梳理排查顺序。适合正在把 Dify Workflow 接入企业微信、CRM、工单系统或内部接口的读者阅读,帮助你把接口调用从一次性跑通推进到可复用、可验证的业务流程。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 3948

C# 二进制文件内容写入类BinaryWriter

程序设计界面 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; usi...

21号先锋者 2278

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

C#二进制文件编程实践

C#读写二进制文件 http://www.cnblogs.com/top5/archive/2011/02/07/1949675.html 本文要介绍的C#本地读写二进制文件,二进制文件指保存在物理磁盘的一个文件。 第一步:读写文件转成流对象。其实就是读写文件流 (FileStream对象,在System.IO命名空间中)。File、FileInfo、FileStream这三个类可以

bcbobo21cn的专栏 1474

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

上一篇: C#导出Excel
下一篇: C#WinForm最简单两DataGridView同步滚动
cg_program
博客等级 码龄19年 245粉丝 147原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址