StreamWriter Truncating Output

John Halliday <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <LISTSERV%[email protected]>
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.