I want to both read from and write to a file. This doesn't work.
static void Main(string[] args) { StreamReader sr = new StreamReader(@"C:words.txt"); StreamWriter sw = new StreamWriter(@"C:words.txt"); }
How can I both read from and write to a file in C#?
You need a single stream, opened for both reading and writing.
FileStream fileStream = new FileStream( @"c:words.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
1.4m articles
1.4m replys
5 comments
56.9k users