using sysytem.Io;
File.Exists() 检查文件是否存在,
Directory.Exists() 检查文件夹是否存在
FileInfo DirectoryInfo 可实例化 对文件的具体操作
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 FileStream fs = new FileStream('文件名',FileMode.Create); //创建文件流 2 3 BinaryWriter w = new BinaryWriter(fs); //打开写入器 4 5 w.Write("写入的内容"); 6 7 w.Close(); //关闭写入器 8 9 fs.Close(); // 关闭文件流
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using(StreamWriter w = File.AppendText("文件名")) 2 { 3 Log("追加的内容", w); 4 w.Close(); 5 6 } 7 8 public static void Log (string message,TextWriter w) 9 { 10 w.WriteLine(message); 11 w.Flush(); 12 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 FileStream fs = new FileStream('文件名',FileMode.Open, FileAccess.Read); //创建文件流 2 3 BinaryReader w = new BinaryReader(fs); //打开阅读器 4 5 w.ReadString(); 6 7 w.Close(); 8 9 fs.Close(); // 关闭文件流 10 11 写入操作