ellapt

T13.3.NumbersOfLines

Jan 31st, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. class NumbersOfLines
  5. {
  6. static void Main()
  7. {
  8. string fileName1 = @"../../Readme.txt";
  9. string fileName2 = @"../../ReadmeWithNumbers.txt";
  10. string line = "";
  11. int lineNum = 0;
  12. try
  13. {
  14. System.Text.Encoding encodingCyr = System.Text.Encoding.GetEncoding(1251);
  15.  
  16. StreamReader streamReader = new StreamReader(fileName1, encodingCyr);
  17.  
  18. StreamWriter streamWriter = new StreamWriter(fileName2,false, encodingCyr);
  19. try
  20. {
  21. while ((line = streamReader.ReadLine()) != null)
  22. {
  23. lineNum++;
  24. line = String.Format("{0,3}.{1}", lineNum,line);
  25. streamWriter.WriteLine(line, true,encodingCyr);
  26. Console.WriteLine(line);
  27. }
  28. }
  29. finally
  30. {
  31. streamReader.Close();
  32. streamWriter.Close();
  33. }
  34. }
  35. catch (System.Exception exc)
  36. {
  37. Console.WriteLine(exc.Message);
  38. }
  39. Console.WriteLine("\nHello, I was made of the Readme.txt file with line numbers added.");
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment