自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows Phone開發(fā)中IsolateStorage用法指引

移動開發(fā)
Windows Phone開發(fā)中IsolateStorage的用法你是否了解,使用IsolateStorage的最大好處就是安全性了,因為只有本程序可以訪問該區(qū)域,而其他程序是無法訪問的。

本文和大家重點學(xué)習(xí)一下Windows Phone開發(fā)中IsolateStorage的用法,在開發(fā)時使用silverlight的特色功能IsolateStorage來保存文本文件、XML文件或INI文件的方式來替代了。

Windows Phone開發(fā)中IsolateStorage

windowsphone7目前版本上已確定沒有文件系統(tǒng)(也就是說filestream、OpenFileDialog這樣的功能都是不能使用了)和數(shù)據(jù)庫系統(tǒng)了,那在開發(fā)時需要保存一些用戶配置信息或臨時數(shù)據(jù)在本地怎么辦?答案是只能使用silverlight的特色功能IsolateStorage來保存文本文件、XML文件或INI文件的方式來替代了。

其實使用IsolateStorage的***好處就是安全性了,因為只有本程序可以訪問該區(qū)域,而其他程序是無法訪問的。這樣也就可以對一此敏感數(shù)據(jù)的保存不用自已再加密了。但是這個區(qū)域是有限的(默認為2GB),不能夠保存很大的數(shù)據(jù),以及長期保存數(shù)據(jù)。如果您非要保存大量數(shù)據(jù),以及長期保存的話,目前只能保存在云端而不是本地。

對于Windows Phone開發(fā)中IsolateStorage的使用,其實也很簡單,和FileStream基本上是一樣的。下面就是一些基本操作的代碼:

1.打開IsolateStorage:

首先引入命名空間System.IO.IsolatedStorage;

打開storageIsolatedStorageFileisf=IsolatedStorageFile.GetUserStoreForApplication();

2.創(chuàng)建文件夾:

isf.CreateDirectory("MyFolder");

3.創(chuàng)建文件:

StreamWriterwriter=newStreamWriter(newIsolatedStorageFileStream("MyFolder\\myFile.txt",FileMode.OpenOrCreate,isf));

writer.WriteLine(“HelloWorld!”);

writer.Close();

4.讀取文件:

StreamReaderreader=newStreamReader(newIsolatedStorageFileStream("MyFolder\\myFile.txt",FileMode.Open,isf));

stringtext=reader.ReadLine();

5.刪除文件:

isf.DeleteFile("MyFolder\\myFile.txt");

6.刪除文件夾:

isf.DeleteDirectory("MyFolder");

7.判斷文件或文件夾是否存在:

isf.FileExit("MyFolder\\myFile.txt");

isf.DirectoryExit("MyFolder");

8.也可以使用Windows Phone開發(fā)中IsolateStorageFileStream來操作文件或文件夾,用法和FileStream基本相同.

相關(guān)的API詳細信息可以查看

http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage(VS.95).aspx

 

責(zé)任編輯:佚名 來源: cnblogs.com
相關(guān)推薦

2010-05-11 16:47:32

Windows Pho

2012-05-08 13:54:40

ToastPrompt

2010-06-11 16:01:26

Windows Pho

2010-04-08 17:40:23

Windows Pho

2010-05-21 16:24:05

Windows Pho

2013-07-30 10:44:31

Windows PhoWindows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2010-06-11 17:01:09

Windows Pho

2010-05-08 16:36:16

Windows Pho

2012-05-25 09:09:25

Windows Pho

2010-06-21 15:39:59

Windows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2010-11-01 14:49:20

Windows PhoWindows Pho

2010-12-21 10:02:48

SilverlightWindows Pho

2013-04-17 13:27:04

Windows PhoWindows Pho
點贊
收藏

51CTO技術(shù)棧公眾號