C# 文件同时读写
2021-07-10 05:09
标签:指定 create string text test tostring flush files file FileAccess.Read指定文件为Read,FileShare.ReadWrite指定其他进程可以读写该文件。如不加FileShare.ReadWrite只加FileAccess.Read则只能同时读,不加FileAccess.Read则同时读也不行。 C# 文件同时读写 标签:指定 create string text test tostring flush files file 原文地址:https://www.cnblogs.com/bwzydr/p/9690602.html//文件冲突测试
FileStream fs1 = new FileStream("readtest1.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
int i1 = fs1.ReadByte();
FileStream fs2 = new FileStream("readtest1.txt",FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
textBox1.Text = i1.ToString()+"\r\n";
FileStream fs3 = new FileStream("readtest1.txt", FileMode.Create,FileAccess.Write);
fs3.WriteByte(24);
fs3.Flush();
int i2 = fs2.ReadByte();
textBox1.Text += i2.ToString();
fs3.Close();
fs2.Close();
fs1.Close();