伙计们,我完全无法得到代码如何比较两个txt文件数据?请帮助解决伙伴们.. [英] Guys, I totally can't get it the code how to compare the two txt file data? Please help to settle guys plz..

查看:71
本文介绍了伙计们,我完全无法得到代码如何比较两个txt文件数据?请帮助解决伙伴们..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string file1 = @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\CoreTouchDownApps\version.txt";
string file2 = @"C:\CoreTouchDownApps\version.txt";
if (string.Equals(file1, file2))
    try
    {
        Process.Start(@"C:\CoreTouchDownApps\CoreTouchDown.exe");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.ReadLine();
    }

else
    try

推荐答案

您正在比较文件名,而不是文件中包含的文件。



你需要读取包含的文件,然后比较包含。
You are comparing the files names, not the files contains.

You need to read the files contains and then compare the contains.


您正在比较这些文件的路径。您需要做的是比较他们的内容。试试这个:

You are comparing the paths to those files. What you need to do is to compare their content. Try this:
string path1 = @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\CoreTouchDownApps\version.txt";
string path2 = @"C:\CoreTouchDownApps\version.txt";

string content1 = File.ReadAllText(path1);
string content2 = File.ReadAllText(path2);

if(content1 == content2)
{
    // do something
}
else
{
    // do something else
}



请注意文件。 ReadAlltext() [ ^ ]将文件内容读入内存。你不应该在大文件中使用它。


Please note that File.ReadAlltext()[^] reads the content of the file into memory. You shouldn't use this with big files.


这篇关于伙计们,我完全无法得到代码如何比较两个txt文件数据?请帮助解决伙伴们..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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