Re: StreamWriter Truncating Output

John Halliday <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <[email protected]>
Sorry folks but I should have waited a bit before sending this.  I figured
this one out - you need to set the AutoFlush to TRUE for the StreamWriter
object.  So,

sw.AutoFlush = true;
... fixed the problem.  I tried to use a counter and manually sw.flush()
every x number of reads but that does seem to work, even when I set the
iteration to 10.  Anyway, the AutoFlush works fine even if it does have a
bit more overhead.

John H.


On 9/12/06, John Halliday <[email protected]> wrote:
>
> Hi folks - my first post here.
>
> I created a console app and use this simple code to read from a text file
> (2091 lines) and the writes out to another file:
>
> string inputfile = "D:/BTCO112.SAMPLE.TXT";
> string outputfile = "D:/BTCO112.OUTPUT.TXT";
>
> StreamReader sr = new StreamReader(inputfile);
> StreamWriter sw = new StreamWriter(outputfile);
> string line = "";
> while ((line = sr.ReadLine()) != null)
> {
> sw.Write(line + "\r\n");
> }
>
> Everything gets written out fine (identical) until the last 51 rows - they
> are missing from the output file.  When I added another 500 lines to the
> input file, the output file was 102 lines shorter this time.  Do I need to
> clear the StreamWriter buffer out now and then?  Why would it stop
> writing?
>
> John Halliday
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.