RE: [DOTNET-CX] StreamWriter Truncating Output
Jeff Ferguson <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
When you're finished with the writes, be sure to call Flush() on the "sw" object. That will flush all of the (most likely) cached data to disk. If you're through with the "sw" object and the write operation, you can also call Close(). > -----Original Message----- > From: Discussion relating to the specifics of the C# and > Managed C++ languages [mailto:[email protected]] > On Behalf Of John Halliday > Sent: Tuesday, September 12, 2006 11:50 AM > To: [email protected] > Subject: [DOTNET-CX] StreamWriter Truncating Output > > 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(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com