• 一起学Windows Phone 7开发(六.Isolate Storage)


    windows phone 7 目前版本上已确定没有文件系统(也就是说filestreamOpenFileDialog这样的功能都是不能使用了)和数据库系统了,那在开发时需要保存一些用户配置信息或临时数据在本地怎么办? 答案是只能使用silverlight的特色功能Isolate Storage来保存文本文件、XML文件或INI文件的方式来替代了。

    其实使用Isolate Storage的最大好处就是安全性了,因为只有本程序可以访问该区域,而其他程序是无法访问的。这样也就可以对一此敏感数据的保存不用自已再加密了。但是这个区域是有限的(默认为2GB),不能够保存很大的数据,以及长期保存数据。如果您非要保存大量数据,以及长期保存的话,目前只能保存在云端而不是本地。

           对于Isolate Storage的使用,其实也很简单,和FileStream基本上是一样的。下面就是一些基本操作的代码:

    1. 打开Isolate Storage

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

    打开storage IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();

    2. 创建文件夹:

     isf.CreateDirectory("MyFolder");

    3. 创建文件:

    StreamWriter writer = new StreamWriter(new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.OpenOrCreate, isf));

    writer.WriteLine(“Hello World!”);

    writer.Close();

     

    4. 读取文件:

    StreamReader reader = new StreamReader(new IsolatedStorageFileStream("MyFolder\\myFile.txt", FileMode.Open, isf));

    string text = reader.ReadLine();

    5. 删除文件:

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

    6. 删除文件夹:

    isf.DeleteDirectory("MyFolder");

    7. 判断文件或文件夹是否存在:

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

    isf.DirectoryExit("MyFolder");

    8.也可以使用IsolateStorageFileStream来操作文件或文件夹,用法和FileStream 基本相同.

    相关的API详细信息可以查看

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

  • 相关阅读:
    Eclipse搭建springboot项目(八)拦截器、过滤器、监听器
    JAVA LOG
    Eclipse搭建springboot项目(七)启动方式
    Eclipse搭建springboot项目(六)全局异常
    Eclipse搭建springboot项目(五)单元测试
    Eclipse搭建springboot项目(四)热部署
    Eclipse搭建springboot项目(三)配置文件自动注入+文件上传需求
    报错
    Eclipse搭建springboot项目(二)springboot目录
    Linux window查询网络端口
  • 原文地址:https://www.cnblogs.com/bicabo/p/1793024.html
Copyright © 2020-2023  润新知