所以我想用这段代码创建一个简单的文本文件。 但是当我打开创建的文件时,文本并没有完全显示, 我得到的唯一文本来自 tb1.text (id[2])。
这里有什么问题吗?
private async void Save_Reg()
{
var myfile = (tb3.Text+".xml");
var folderUsed = ApplicationData.Current.LocalFolder;
var folderOp = Windows.Storage.CreationCollisionOption.ReplaceExisting;
var createFile = await folderUsed.CreateFileAsync(myfile, folderOp);
var password = tb2.Text;
var recov = tb1.Text;
string[] id = { myfile,password, recov };
await Windows.Storage.FileIO.WriteTextAsync(createFile, id[0]);
await Windows.Storage.FileIO.WriteTextAsync(createFile, id[1]);
await Windows.Storage.FileIO.WriteTextAsync(createFile, id[2]);
}
最佳答案
is there anything wrong here?
是的。 WriteTextAsync
替换当前文件的内容。它相当于同步 File.WriteAllText
方法。如果你想追加,你需要AppendTextAsync
.
或者,连接 ID,以便您知道要写入的全部内容,然后仅调用一次 WriteTextAsync
。
关于c# - writealltextasync 不会将所有文本写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13657950/