c#怎样复制打开的文件并清空内容
(2023-02-28 16:29:41)
标签:
c复制打开的文件并清空清空文件内容 |
分类: 编程 |
using System.IO;
......
string sourceFile = @"c:\temp\1.txt";
string destinationFile = @"c:\temp\2.txt";
FileStream fs = new FileStream(sourceFile,FileMode.Create);
StreamWriter sw1 = new StreamWriter(fs);
......
sw1.Flush();//缓冲区数据写入到文件中
File.Copy(sourceFile,destinationFile);
fs.SetLength(0);//打开的文件清空内容
......
sw1.Close();