string fileText;
using (var reader = File.OpenText(pathToSave)) {
fileText = await reader.ReadToEndAsync();
reader.Close();
}
using (var stream = File.Open(pathToSave, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) {
Byte[] text = new UTF8Encoding(true).GetBytes("test1" + Environment.NewLine);
stream.Write(text, 0, text.Length);
text = new UTF8Encoding(true).GetBytes("test2" + Environment.NewLine);
stream.Write(text, 0, text.Length);
stream.Close();
}
I don't operate with files anywhere else.
I always close file descriptors after reading / writing, but I still get an error, that the file is used by another process.
What do I do wrong?
The error appears on FileMode.Append
.