Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This program demonstrates writing to and reading from a filesystem using C# StreamWriter and StreamReader
- //L.Mohan Arun
- //x-x
- using System;
- using System.IO;
- namespace FileHandlingDemo
- {
- class ProgramFRW
- {
- static void Main(string[] args)
- {
- string filename = "C:\\New Folder\\Myfile.txt";
- //if you are using the using keyword you need to import System-comment
- using (StreamWriter sw = new StreamWriter(filename))
- {
- sw.WriteLine("StreamWriter and StreamReader demo!");
- sw.Close();
- }
- using (StreamReader sr = new StreamReader(filename))
- {
- while (sr.EndOfStream != true)
- {
- Console.WriteLine(sr.ReadLine());
- }
- sr.Close();
- }
- Console.WriteLine("Press any key to continue!");
- Console.Read();
- }
- }
- }
Add Comment
Please, Sign In to add comment