StreamReader and StreamWrite for Text file
-
Hi, I am using Text file. Using StreamWriter I am writing some line in the file. Then I close that file using StreamWriter.Close() After the closing the file. I am again opening the same file for reading purpose. I read some data for checking and again write into the same file using StreamWriter. At that time is showing me error "Cannot write to closed Textwriter". I want to use the same file for writing.How can i do? Thanks Sjs
-
Hi, I am using Text file. Using StreamWriter I am writing some line in the file. Then I close that file using StreamWriter.Close() After the closing the file. I am again opening the same file for reading purpose. I read some data for checking and again write into the same file using StreamWriter. At that time is showing me error "Cannot write to closed Textwriter". I want to use the same file for writing.How can i do? Thanks Sjs
-
Hi, I am using Text file. Using StreamWriter I am writing some line in the file. Then I close that file using StreamWriter.Close() After the closing the file. I am again opening the same file for reading purpose. I read some data for checking and again write into the same file using StreamWriter. At that time is showing me error "Cannot write to closed Textwriter". I want to use the same file for writing.How can i do? Thanks Sjs
hi, I dont know which framework are u using? but if u r using framework 3.5, I recommed u to use the streamreader and streamwriter objects in using keyword e.g., using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine("This"); sw.WriteLine("is some text"); sw.WriteLine("to test"); sw.WriteLine("Reading"); } using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { Console.WriteLine(sr.ReadLine()); } } Hope this helps. Regards, Atif Ali Bhatti.