开发者

C# - Using File.WriteAllLines

Will the below method overwrite the output file (process.txt) ?

private static void CompareOrig()
{

    File.WriteAllLines("process.txt",
    File.ReadAllLines("process2.txt").Except(File.ReadAllLines("process.txt")));

}

Added Info:

The problem is that when the lines are read from process2.txt, they are written to the process.开发者_Python百科txt file, hence overwriting all existing data in that file. Instead how could I append the output to process.txt? e.g.

File.AppendAllText("process.txt")


Will the below method overwrite the output file (process.txt) ?

Yes

If so, how can this be avoided?

Use another filename for writing.

If you meant "will it be overwritten before it is completely read" then the answer is No and you have no problem.

But splitting this up with one or two variables would make it so much more readable. If it makes you doubt, so will it make the reader. Over and over again.


A little old, but for anyone reading. If you only want to append to existing file use.

File.WriteLine("Text");

instead of

File.WriteAllLines("Text);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜