zoukankan      html  css  js  c++  java
  • Windows Phone 7独立存储空间IsolatedStorage

    Windows Phone 7的solatedStorage可以用来保存应用程序的数据和设置。结构图如下

    一、相关类

      1.IsolatedStorageFile类

        1)描述:表示在独立存储空间中的文件和目录

        2)重要属性

          long AvailableFreeSpace:IsolatedStorage有效的剩余空间。

          long Quota:IsolatedStorage的总容量。

        3)重要方法

          void CreateDirectory(string dir):在IsolatedStorage中创建一个指定的目录。

          IsolatedStorageFileStream CreateFile(string path):在IsolatedStorage中创建一个文件。

          void DeleteDirectory(string dir):删除IsolatedStorage的指定目录。

          void DeleteFile(string file):删除IsolatedStorage的指定文件。

          bool DirectoryExists(string path):判断IsolatedStorage中是否存在指定的目录,如果存在则返回true。

           bool FileExists(string path):判断IsolatedStorage中是否存在指定的文件,如果存在则返回true。

          string[] GetDirectoryNames():获取IsolatedStorage中的所有目录名称。

          string[] GetFileNames():获取IsolatedStorage中的所有文件名称。

          static IsolatedStorageFile GetUserStoreForApplication():由一个应用程序调用,获得用户范围可以使用的独立存储。

          IsolatedStorageFileStream OpenFile(string path, FileMode mode):打开一个指定的文件。

      2.IsolatedStorageFileStream类

        1)描述:打开一个文件流。

    二、应用

      1.创建并写入文件

        首先我们获取空间

        var appStorage = IsolatedStorageFile.GetUserStoreForApplication();

        保存的文件名
                string fileName = "simple.txt";

        打开流
                using (var file=appStorage.OpenFile(fileName,System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write))
                {
                    using (var writer=new System.IO.StreamWriter(file))
                    {

          写入数据
                        writer.Write(this.inputInfo.Text);
                    }
                }  

        2.打开并读取文件

          using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (StreamReader reader=new StreamReader(store.OpenFile("simple.txt",FileMode.Open,FileAccess.Read)))
                    {
                        inputInfo.Text = reader.ReadToEnd();
                    }
                } 

    三、源码下载

        点击这里下载示例源码

  • 相关阅读:
    直击微软第九频道著名主持Robert Green 对话一站式示例代码库大老板梁梅女士
    微软发布中文版一站式示例代码浏览器
    每日一例,练就编程高手
    微软发布Visual Studio 2012 示例代码浏览器
    微软发布Sample Browser for Windows 8版:5000示例代码,"触手可及"
    arthas使用总结
    前端如何生成二维码
    golang的helloworld以及nonmain package的troubleshooting
    监控文件的网页工具
    postfix + courierimap + squirrelMail 邮件服务器
  • 原文地址:https://www.cnblogs.com/salam/p/1918994.html
Copyright © 2011-2022 走看看