[英]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.