Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream TextReader to a File

I have a TextReader object.

Now, I want to stream the whole content of the TextReader to a File. I cannot use ReadToEnd() and write all to a file at once, because the content can be of high size.

Can someone give me a sample/tip how to do this in Blocks?

like image 311
BennoDual Avatar asked Sep 02 '25 05:09

BennoDual


1 Answers

using (var textReader = File.OpenText("input.txt"))
using (var writer = File.CreateText("output.txt"))
{
    do
    {
        string line = textReader.ReadLine();
        writer.WriteLine(line);
    } while (!textReader.EndOfStream);
}
like image 99
Tony Avatar answered Sep 05 '25 00:09

Tony