Please login to save your progress.
Files and Directories
Exercise: Writing to a file
Goal
Write to the local file Actors.txt
- Create a file stream called file using the local file "Movies.txt" to overwrite the file
- Create a stream writer called writer using the file stream
- Write each item in the list actors to the file on a new line. Use a foreach loop for this
- After the loop, close the reader.
x
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
List<string> actors = new List<string>()
10
{
11
"Mark Hamill",
12
"Harrison Ford",
13
"Carrie Fisher"
14
};
15
16
// Your code here.
17
}
18
}
Page 12 of 20