根据内容对文件进行比较

实现效果:

  

知识运用:

  StreamReader类用来实现TextReader抽象类   使其以一种特定的编码从字节流中读取字符

  其ReadToEnd方法用来从当前流的当前位置到末尾读取流  

  public override string ReadToEnd()      //如果当前位置位于流的尾端 则返回空字符串 ("")

实现代码:

        private void button3_Click(object sender, EventArgs e)
        {
            StreamReader sr1 = new StreamReader(textBox1.Text);
            StreamReader st2 = new StreamReader(textBox2.Text);
            if (object.Equals(sr1.ReadToEnd(), st2.ReadToEnd()))
            {
                MessageBox.Show("两个文件相等");
            }
            else { MessageBox.Show("两个文件不相等"); }
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10226607.html