添加文本文件的Windows Store应用程序(窗口RT) [英] Appending Text to File Windows store Apps (windows RT)
问题描述
我要寻找一种方式来字符串文本追加到在Windows Store应用的文件。我试图读取该文件,然后创建一个新的覆盖,但Windows应用商店的应用C#不喜欢C,其中当创建具有相同名称的新文件覆盖旧的工作之一。目前我的代码是开放的旧文件,阅读它的内容,删除它并创建一个新的与我阅读的内容再加上我想追加的内容。
我知道有一个更好的办法,但我似乎无法找到它。所以,我怎么可能文本追加到在Windows Store应用(视窗RT)
I am looking for a way to append strings-text to a file in a Windows Store App. I have tried reading the file and then creating a new one to overwrite it but Windows Store Apps C# does not work like C where when creating a new file with the same name overwrites the old one. Currently my code is opening the old file, reading it's contents, deleting it and creating a new one with the content I read plus the content I wish to append. I know there is a better way but I cannot seem to find it. So How may I append text to an already existent file in a Windows Store App (Windows RT)?
编辑一个已经存在的文件 -
EDIT--
我试过这个
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("feedlist.txt");
await Windows.Storage.FileIO.AppendTextAsync(file, s);
但我不断收到 System.UnauthorizedAccessException的
$根据MSDN b $ b。这种情况发生时,该文件是只读(我用鼠标右键单击性能检查,这不是),如果我没有必要的权限来访问该文件
我该怎么办?
but I keep getting System.UnauthorizedAccessException
according to MSDN this happens when the file is readonly (I checked with right click properties, it's not) and if I do not have the necessary privileges to access the file
what should I do?
推荐答案
您可以使用的 FileIO专注类追加到一个文件中。例如...
You can use the FileIO class to append to a file. For example ...
// 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");
这篇关于添加文本文件的Windows Store应用程序(窗口RT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!