标签:reader filter return object int data- 建立 inf 操作
FileStream, MemoryStream, BufferedStream
BinaryReader和BinaryWriter
TextReader和TextWriter
StreamReader和StreamWriter
StringReader和StringWriter
FileStream fs = new FileStream(@"c:\t\c", FileMode.Create);
StreamWriter writer = new StreamWriter(fs);
FileInfo 具体的文件
File 提供static方法
DirectoryInfo 具体的文件夹
Directory 提供static方法
FileSystemInfo
是FileInfo及DirectoryInfo的父类
Path 文件路径类(路径拆分和查找)
new FileInfo(文件无聊路径)
class Program
{
static void Main(string[] args) {
ListFiles(new DirectoryInfo(@"F:\download"));
}
public static void ListFiles(FileSystemInfo info) {
if (!info.Exists) return;
//info当成一个为DirectoryInfo,如果不成功则当成null
DirectoryInfo dir = info as DirectoryInfo;
if (dir == null) return; //不是目录
FileSystemInfo[] files = dir.GetFileSystemInfos();
for (int i = 0; i < files.Length; i++) {
FileInfo file = files[i] as FileInfo;
if (file != null) { //是文件
Console.WriteLine(
file.FullName + "\t" + file.Length);
} else {
ListFiles(files[i]); //对于子目录,进行递归调用
}
}
}
}
class Program
{
static void Main(string[] args) {
const string path = @"G:\Dev-Cpp\代码大全\OS实验";
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.Filter = "*.cpp";
watcher.NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite | NotifyFilters.FileName |
NotifyFilters.DirectoryName;
//事件处理函数
watcher.Changed += new FileSystemEventHandler(onChanged);
watcher.Created += new FileSystemEventHandler(onChanged);
watcher.Deleted += new FileSystemEventHandler(onChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
//开启监视
watcher.EnableRaisingEvents = true;
//等待用户输入q才结束程序
Console.WriteLine("Press ‘q‘ to quit the sample.");
while (Console.Read() != ‘q‘) ;
}
//事件处理函数
public static void onChanged(object source, FileSystemEventArgs e) {
//显示哪些文件做了哪些修改
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}
public static void OnRenamed(object source, RenamedEventArgs e) {
//显示被更改的文件名
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
}
//在目录下新建一个文件即能在程序显示对 .cpp文件进行的操作类型
标签:reader filter return object int data- 建立 inf 操作
原文地址:http://www.cnblogs.com/douzujun/p/6731518.html