Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that reads a text file and inserts line numbers in front of each of its lines. The result should be written to another text file. Use StreamReader in combination with StreamWriter. */
- namespace _02.Line_Numbers
- {
- using System.IO;
- using System.Text;
- class LineNumbers
- {
- static void Main(string[] args)
- {
- using (var reader = new StreamReader("../../LineNumbers.cs"))
- {
- using (var stream = new FileStream("../../NumberedLines.txt", FileMode.Create))
- {
- using (var writer = new StreamWriter(stream, Encoding.ASCII, 4096))
- {
- string textLine = reader.ReadLine();
- int lineNum = 0;
- while (textLine != null)
- {
- lineNum++;
- writer.WriteLine("#{0,2} {1}", lineNum, textLine);
- textLine = reader.ReadLine();
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement