如何比较两个txt文件,看看它们是否相同? [英] How to compare two txt files to see if they are the same?

查看:131
本文介绍了如何比较两个txt文件,看看它们是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个比较两个txt文件的程序,看看它们是否相同。该程序将向用户提供两个txt文件,然后进行比较。如果它们是相同的,它应该打印是,但如果不是,它应该打印否,然后是每个文件的第一行是不同的。我知道如何向用户提供文件名,但我不知道如何比较它们。

I am trying to write a program that compares two txt file to see if they are the same. The program is to promt the user for two txt files and then compare them. If they are the same it should print yes but if not it should print no followed by the first line of each file that is diffeent. I know how to promt the user for the filename but i do not know how to compare them.

推荐答案

对于小文件,两者都可以作为字符串读入内存比较等式如:
For small files, both could be read into memory as strings and compared for equality as in:
展开 | 选择 | Wrap | 行号


我已将它们导入然后co它们!我该怎么做?
i have import them in and then comare them! How do i do that?


展开 | 选择 | Wrap | 行号


这篇关于如何比较两个txt文件,看看它们是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆