//string记录到文件
string a= content;//采样结果
if (!File.Exists("e:\newfile\newtxt.txt"))
{
new FileStream(" e:\newfile\newtxt.txt", FileMode.Create, FileAccess.Write);//创建写入文件
}
FileStream fs3 = new FileStream("e:\newfile\newtxt.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw3 = new StreamWriter(fs3);
sw3.Write(a+ "
");//开始写入值
sw3.Close();
fs3.Close();
//byte[]记录到文件
/**文件记录 begin*/
FileStream fs = new FileStream(SettingsUnit.UpdateDataPath, FileMode.Append, FileAccess.Write);
StreamWriter sw1 = new StreamWriter(fs);
string filePath = SettingsUnit.UpdateDataPath;
FileInfo fileInfo = new FileInfo(filePath);
double FileLength = fileInfo.Length;//取文件长度(字节)
if (ReturnUpdate1.Start == "0" && FileLength > 10000)
{
sw1.Close();
fs.Close();
fs = new FileStream(SettingsUnit.UpdateDataPath, FileMode.Truncate, FileAccess.ReadWrite);//清空文件内容
fs.Close();
fs = new FileStream(SettingsUnit.UpdateDataPath, FileMode.Append, FileAccess.Write);//重新打开文件
sw1 = new StreamWriter(fs);
}
fs.Write(buffernew, 0, buffernew.Length); //将byte数组写入文件中
sw1.Close();
fs.Close();
/**文件记录 end*/