zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C#判断文件是否正在使用

c#文件 判断 是否 正在 使用
2023-09-27 14:20:54 时间
 private bool IsFileInUse(string strFileName)
        {
            if (!File.Exists(strFileName))
                return false;
            bool bRet = true;
            FileStream fs = null;
            try
            {
                fs = new FileStream(strFileName, FileMode.Open, FileAccess.Write, FileShare.None);
                bRet = false;
            }
            catch
            {

            }
            finally
            {
                if (fs != null)
                    fs.Close();
            }
            return bRet;
        }