一、创建文件夹,例:
1 if (!Directory.Exists(path)) 2 { 3 Directory.CreateDirectory(path); 4 }
二、创建文件,例:
1 global::System.IO.FileInfo josnfile = new global::System.IO.FileInfo(JsonPath); 2 if (!josnfile.Exists) 3 { 4 // 创建map.json文件 5 FileStream fs = new FileStream(JsonPath, FileMode.CreateNew, FileAccess.ReadWrite); 6 StreamWriter sw = new StreamWriter(fs); 7 sw.Write("[]"); 8 sw.Flush(); 9 sw.Close(); 10 //Thread.Sleep(300); 11 }
三、读取文件内容,例:
1 using (FileStream fs = new FileStream(JsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) 2 { 3 using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("gb2312"))) 4 { 5 noteIsSubmit = sr.ReadToEnd().ToString().Contains(FileName); 6 } 7 }
四、复制文件,例:
1 global::System.IO.FileInfo _f = new global::System.IO.FileInfo(path); 2 try 3 { 4 if (!_f.Exists) 5 { 6 //复制讲稿文件 7 global::System.IO.FileInfo copyFile = new global::System.IO.FileInfo(FileURL); 8 copyFile.CopyTo(path); 9 } 11 } 12 catch (Exception ex) 13 { 14 Logger.D("NoteMake讲稿制作发生异常:", ex.Message); 15 }
时间: 2024-12-19 10:22:19