所以我想用这段代码创建一个简单的文本文件.但是当我打开创建的文件时,文本没有完全显示,我得到的唯一文本来自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]);
}
Run Code Online (Sandbox Code Playgroud)
这里有什么不对吗?
是.替换当前文件的内容.它等同于同步方法.如果你想追加,你需要.WriteTextAsync
File.WriteAllText
AppendTextAsync
或者,连接id以便您知道要写入的完整内容,然后WriteTextAsync
只调用一次.