zoukankan      html  css  js  c++  java
  • C#监听文件

    //全局变量 

    public static FileSystemWatcher Watcher;

           /// <summary>
            /// 设置监听配置
            /// </summary>
            /// <returns>ture/false</returns>
            public static Boolean SetMonitorFile()
            {
                try
                {
                    Watcher = new FileSystemWatcher();
                    Watcher.Filter = "*.txt";
                    Watcher.Path = "d:\"; //路径
                    Watcher.NotifyFilter = NotifyFilters.Size; //文件大小改变
                    //文件改变事件
                    Watcher.Changed += new FileSystemEventHandler(Watcher_Changed); ;
                    //文件创建事件       
                    Watcher.Created += new FileSystemEventHandler(Watcher_Created);
                    //文件删除事件
                    Watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);
                    //文件重命名事件
                    Watcher.Renamed += new RenamedEventHandler(Watcher_Renamed);
                    //设置监听子目录
                    Watcher.IncludeSubdirectories = false;
                    //开始进行监听(其实此处是标示是否进行事件监听和抛出)
                    Watcher.EnableRaisingEvents = true;
                    //watcher.EndInit();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }

  • 相关阅读:
    Java实体书写规范
    Mybatis配置中遇到的问题和问题分析
    Ubuntu下eclipse的Extjs提示插件安装
    Ubuntu中root用户和user用户的相互切换
    ubuntu下启动和关闭tomcat的简单方法
    Ubuntu上安装Maven Eclipse以及配置
    IE8兼容<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    心情
    更改Eclipse下Tomcat的部署目录
    Tomcat:IOException while loading persisted sessions: java.io.EOFException 解决
  • 原文地址:https://www.cnblogs.com/-lxl/p/4843853.html
Copyright © 2011-2022 走看看