public void Write(string scoredata)
{
FileStream fs = null;
string filePath = "F:\\score.txt";//文件位置
//将待写的入数据从字符串转换为字节数组
Encoding encoder = Encoding.UTF8;
byte[] bytes = encoder.GetBytes(scoredata);
try
{
fs = File.OpenWrite(filePath);
//设定书写的开始位置为文件的末尾
fs.Position = fs.Length;
//将待写入内容追加到文件末尾
fs.Write(bytes, 0, bytes.Length);
}
catch (Exception ex)
{
Console.WriteLine("文件打开失败{0}", ex.ToString());
}
finally
{
fs.Close();
}
Console.ReadLine();
}//文件读取函数
转载于:https://my.oschina.net/u/1446208/blog/372348