[英]Data storing in a mobile application(windows 8)
我需要存储一些数据以用于基于Windows8的移动应用程序。 数据需要重用。 例如,需要存储4个电话号码以发送消息,并存储另一个电话号码以发送呼叫。 我如何在这里存储数据。 我听说过隔离存储。 是这样还是可以将其连接到数据库。 如果应用程序连接到数据库,会不会太繁重?
不知道连接数据库是什么意思。
在Windows Phone 8中,隔离存储是指每个应用程序在手机上的存储,我不认为(我不确定)其他应用程序可以访问它。 基本上,如果您需要保存某些内容,它将看起来像这样。 以下代码用于保存内容:
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
//create new file
using (StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("myFile.txt", FileMode.Create, FileAccess.Write, myIsolatedStorage)))
{
string someTextData = "This is some text data to be saved in a new text file in the IsolatedStorage!";
writeFile.WriteLine(someTextData);
writeFile.Close();
}
要随时访问该文件,您只需执行以下操作:
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read);
using (StreamReader reader = new StreamReader(fileStream))
{ //Visualize the text data in a TextBlock text
this.text.Text = reader.ReadLine();
}
链接在这里。 http://www.geekchamp.com/tips/all-about-wp7-isolated-storage-read-and-save-text-files
隔离存储允许您将文件永久存储在此处,即使用户退出应用程序也可以对其进行检索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.