lmohanarun

C# CODE SNIPPET #A4C39DXB

Dec 17th, 2015
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. //This program demonstrates writing to and reading from a filesystem using C# StreamWriter and StreamReader
  2. //L.Mohan Arun
  3. //x-x
  4. using System;
  5. using System.IO;
  6. namespace FileHandlingDemo
  7. {
  8. class ProgramFRW
  9. {
  10. static void Main(string[] args)
  11. {
  12. string filename = "C:\\New Folder\\Myfile.txt";
  13. //if you are using the using keyword you need to import System-comment
  14. using (StreamWriter sw = new StreamWriter(filename))
  15. {
  16. sw.WriteLine("StreamWriter and StreamReader demo!");
  17. sw.Close();
  18. }
  19. using (StreamReader sr = new StreamReader(filename))
  20. {
  21. while (sr.EndOfStream != true)
  22. {
  23. Console.WriteLine(sr.ReadLine());
  24. }
  25. sr.Close();
  26. }
  27. Console.WriteLine("Press any key to continue!");
  28. Console.Read();
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment