zoukankan      html  css  js  c++  java
  • 判断文件是否正在使用

    代码
     public bool IsFileInUse(string fileName)
            {
                
    bool inUse = true;
                
    if (File.Exists(fileName))
                {
                    FileStream fs 
    = null;
                    
    try
                    {
                        fs 
    = new FileStream(fileName, FileMode.Open, FileAccess.Read,FileShare.None);
                        
    if (fs.CanWrite)
                        {
                            inUse 
    = false;
                        }
                        
    else
                            inUse 
    = true;
                        inUse 
    = false;
                    }
                    
    catch
                    {
                        
    // exception....
                    }
                    
    finally
                    {
                       
    if (fs != null)

                            fs.Close();
                    }
                   
    return inUse;//by yl  true表示正在使用,false没有使用

                }
                
    else
                {
                   
    return false;//文件不存在,肯定没有被使用
                }

            }
  • 相关阅读:
    python 协程
    python 进程池的使用
    python 多进程数据交互及共享
    python 多进程
    技术博客与技术日记
    理解闭包
    jWriter一个基于jQuery的阅读写作网站的效果库
    ubuntu下phpmyadmin配置问题解决
    避免明文保存用户密码
    如何用css实现类似简书的纵向导航/竖排导航
  • 原文地址:https://www.cnblogs.com/hantianwei/p/1634253.html
Copyright © 2011-2022 走看看