Empty line in .Net File.WriteAllLines - error?

everything

This question is related to two methods in System.IO.File:

File.WriteAllLines and File.ReadAllLines

When I save List [string] ListA with

File.WriteAllLines("filename",ListA.ToArray()); 

An empty line will be added to the output file.

So every time I load this file by calling File.ReadAllLines , I always get another empty line.

This is annoying because I have to "delete" it manually each time.

Does anyone have the same problem? And how do you deal with this?

thanks

0
c #
source share
1 answer

No, I can not reproduce this:

 using System; using System.Collections.Generic; using System.IO; class Test { static void Main() { string[] lines = { "first", "second", "third" }; for (int i = 0; i < 10; i++) { File.WriteAllLines("test.txt", lines); lines = File.ReadAllLines("test.txt"); Console.WriteLine("Number of lines read: {0}", lines.Length); } } } 

It sounds like what you are doing with the lines ... which you did not tell us.

+2
source share

All Articles