如何锁定文件 [英] How to lock file
本文介绍了如何锁定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我如何锁定在C#文件
please tell me how to lock file in c#
感谢
推荐答案
只要以独占方式打开它:
Simply open it exclusively:
using (FileStream fs =
File.Open("MyFile.txt", FileMode.Open, FileAccess.Read, FileShare.None))
{
// use fs
}
参考。
更新:为响应从海报发表评论:据网上的 MSDN多科,File.open方法是支持.NET精简框架1.0和2.0。
Update: In response to comment from poster: According to the online MSDN doco, File.Open is supported in .Net Compact Framework 1.0 and 2.0.
这篇关于如何锁定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文