-1
我将文本保存为.txt文件。之后我想添加一些新的文本到文件中。如果我运行代码编写新文本,它会覆盖旧内容。我怎样才能防止这一点?如何不覆盖文件
using UnityEngine;
using System.IO;
public class Level02WON : MonoBehaviour
{
void OnTriggerEnter()
{
string line = "Level02 = true";
System.IO.StreamWriter file =
new System.IO.StreamWriter(@"C:\Users\Public\Cubator\Level Data\Level02DATA.txt");
file.WriteLine(line);
file.Close();
}
}
'FileMode.Append' – BradleyDotNET
检查此链接https://msdn.microsoft.com/en-us /library/system.io.file.appendtext(v=vs.110).aspx – Adds
@Adds:甚至更简单,AppendAllText打开文件进行追加或创建它,如果它不存在,则写入新内容,并在一次函数调用中关闭文件。 –