c#读取并异步写入文件
2020-12-30 01:28
标签:readline read time cst 结束 var syn each 异步写入 1.同步读取和写入 2.异步写入 c#读取并异步写入文件 标签:readline read time cst 结束 var syn each 异步写入 原文地址:https://www.cnblogs.com/Leo_wl/p/13278465.html StreamReader objReader = new StreamReader("E://workspace//zzz//read.txt", Encoding.GetEncoding("utf-8"));
string sLine = "";
ArrayList LineList = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null && !sLine.Equals(""))
LineList.Add(sLine);
}
objReader.Close();
string str = "";
foreach (var item in LineList)
{
str += item + Environment.NewLine;
}
string filePath = "E://workspace//zzz//" + DateTime.Now.Millisecond + ".txt";
FileStream fs = new FileStream(filePath, FileMode.Create);
StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("utf-8"));
//开始写入
sw.Write(str);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
///