I am trying to write to a file using StreamWriter, but for some reason it is cutting off my data. I have set up a simple problem of what is going on below:

TextWriter TestOut = new StreamWriter("test.txt");

            for (int i = 1; i < 1001; i++)
            {
                Console.WriteLine("i = " + i);
                TestOut.WriteLine("i = " + i);
            }

text.txt ends in:
i = 462
i = 463
i = 464
i = 465
i = 466
i = 467
i

console ends in:
i = 997
i = 998
i = 999
i = 1000


Does anyone know why it is cutting off my file??? Is there some way to declare a larger file. I am using this in a program where I am dealing with almost 4 million lines per text file.

Recommended Answers

All 3 Replies

You need to Flush() and Close() your file after you are done writing to it.

Thank you!!!

Your welcome. Please mark resolved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.