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;//文件不存在,肯定没有被使用
                }

            }
  • 相关阅读:
    curl命令详解
    Linux 下 set env export declare浅浅 set和shopt命令详解--(shell定制) (转载)
    ps aux指令詳解
    smb设置参考手册 --详细参数
    Ajax
    JSON浅谈
    Date类型
    笔记本电脑不能上网的问题
    editplus 初步设置
    w10 系统升级
  • 原文地址:https://www.cnblogs.com/hantianwei/p/1634253.html
Copyright © 2011-2022 走看看