创建文本文件:
var myFile = "test";
var folderUsed = Windows.Storage.ApplicationData.Current.LocalFolder;
var fileOption = Windows.Storage.CreationCollisionOption.ReplaceExisting;
var createdFile = await folderUsed.CreateFileAsync(myFile, fileOption);
将字符串写入创建的文本文件:
var writeThis = "write this ";
await Windows.Storage.FileIO.WriteTextAsync(createdFile, writeThis);
但是,它没有指定将在哪个部分创建文本文件,我想在我的应用程序包内创建它,而不是在我计算机的其他地方,这可能吗?
其次,当我再次执行第二个代码时,我希望我的文件被写成“write this write this”,而不是替换旧文件并创建另一个文件。
最佳答案
你应该使用
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
因为安装文件夹等其他文件夹被限制,不允许进行读写操作。 Windows 应用商店应用在这方面受到很大限制。
这个链接也很有用:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758325.aspx
关于c# - Windows Metro 应用程序 - 在 C# 中写入和读取文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13641143/