c# – 将文本附加到文件Windows存储应用程序(Windows RT)
发布时间:2020-12-15 06:42:38 所属栏目:百科 来源:网络整理
导读:我正在寻找一种将字符串文本附加到 Windows Store App中的文件的方法.我已经尝试阅读文件,然后创建一个新的覆盖它,但是Windows Store Apps C#不像C那样工作,当创建一个具有相同名称的新文件时,它将覆盖旧的文件.目前我的代码是打开旧文件,读取它的内容,删除
我正在寻找一种将字符串文本附加到
Windows Store App中的文件的方法.我已经尝试阅读文件,然后创建一个新的覆盖它,但是Windows Store Apps C#不像C那样工作,当创建一个具有相同名称的新文件时,它将覆盖旧的文件.目前我的代码是打开旧文件,读取它的内容,删除它,并创建一个新的内容,我阅读加上我想追加的内容.
我知道有更好的方法,但我似乎找不到.那么如何在Windows Store App(Windows RT)中将文本附加到已经存在的文件? 编辑 – 我试过了 var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; var file = await folder.GetFileAsync("feedlist.txt"); await Windows.Storage.FileIO.AppendTextAsync(file,s); 但我不断得到System.UnauthorizedAccessException 解决方法
您可以使用
FileIO类附加到文件.例如 …
// Create a file in local storage var folder = ApplicationData.Current.LocalFolder; var file = await folder.CreateFileAsync("temp.txt",CreationCollisionOption.FailIfExists); // Write some content to the file await FileIO.WriteTextAsync(file,"some contents"); // Append additional content await FileIO.AppendTextAsync(file,"some more text"); 查看File Access Sample了解更多的例子. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |