Re: StreamWriter Truncating Output
Peter Ritchie <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
Be sure to call Close on your streams. You can do this automatically as
the object goes out of scope if you use the "using" statement
(recommended):
using(StreamReader sr = new StreamReader(inputfile))
{
using(StreamWriter sw = new StreamWriter(outputfile))
{
string line = "";
while ((line = sr.ReadLine()) != null)
{
sw.Write(line + "\r\n");
}
}
}
On Tue, 12 Sep 2006 12:50:16 -0400, 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?
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com