In the following code I get the error "stream was not writable":
class Class1
{
private static void Main()
{
FileStream fs = new FileStream("C:\fFile.txt",
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.ReadWrite);
StreamReader r = new StreamReader(fs);
string t = r.ReadLine();
r.Close();
Console.WriteLine(t);
StreamWriter w = new StreamWriter(fs);
w.WriteLine("string");
w.Flush();
w.Close();
fs.Close();
}
}
The error occurs at this line StreamWriter w = new StreamWriter(fs);
Why is this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…