程 序 人 生

[每个人都是工程师,书写着属于自己的人生代码!--林海]
posts - 41, comments - 14, trackbacks - 0, articles - 2
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var contant = new byte[fs.Length];
fs.Read(contant, 0, (int)fs.Length);
string res = Encoding.Default.GetString(contant);

 
这样的情况,不单要与只读方式打开文件,需要共享锁,而且必须要选择flieShare方式为ReadWrite。因为随时有其他程序对其进行写操作。