新浪博客

c#怎样复制打开的文件并清空内容

2023-02-28 16:29阅读:
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();

我的更多文章

下载客户端阅读体验更佳

APP专享