[英]Write to a text file in my project's assets folder Windows Phone 8.1
[英]Read text file in project folder in Windows Phone 8.1 Runtime
我希望在第一次启动应用程序时将我的项目的根文件夹中的一个文件.txt读入我的数据库,但我不知道该怎么做。 任何人都知道我该怎么做,请帮助我...谢谢
我在Windows Phone 8.1 Runtime中工作。
如果您想从项目中读取文件,您可以这样做:
string fileContent;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///example.txt"));
using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
fileContent = await sRead.ReadToEndAsync();
另外,请确保您已将文件的构建操作设置为内容 (它应该是默认值)。
访问文件的方式略有不同:
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("sample.txt");
var contents = await Windows.Storage.FileIO.ReadTextAsync(file);
它只能在Windows Phone 8.1
运行。 没有以前版本的Windows Phone 8
( Windows Phone 8
, Windows Phone 7
)可以运行您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.