时间:2016-02-15 21:58 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【.Net笔记:System.IO之windows文件操作的深入分析】,下面是详细的讲解!
.Net笔记:System.IO之windows文件操作的深入分析
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace UseFileSystemWatcher
{
class Program
{
static void Main(string[] args)
{
//声明要监视的目录
string watchPath="D:\\watch";
FileSystemWatcher watcher=new FileSystemWatcher(watchPath, "*.*");
//添加文件变化处理事件
watcher.Changed +=new FileSystemEventHandler(Watcher_Changed);
//添加文件创建处理事件
watcher.Created +=new FileSystemEventHandler(Watcher_Created);
//添加文件删除处理事件
watcher.Deleted +=new FileSystemEventHandler(Watcher_Deleted);
//添加错误处理
watcher.Error +=new ErrorEventHandler(Watcher_Error);
//启动监视
watcher.EnableRaisingEvents=true;
Thread.Sleep(1000 * 60);
Console.WriteLine("press any key to exit..");
Console.Read();
}
static void Watcher_Error(object sender, ErrorEventArgs e)
{
Console.WriteLine("错误:" + e.ToString());
}
static void Watcher_Deleted(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType + ":" + e.FullPath);
}
static void Watcher_Created(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType + ":" + e.FullPath);
}
static void Watcher_Changed(object sender, FileSystemEventArgs e)
{
Console.WriteLine(e.ChangeType + ":" + e.FullPath);
}
}
}
关于.Net笔记:System.IO之windows文件操作的深入分析的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
