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();
                    }
                } 

    三、源码下载

        点击这里下载示例源码

  • 相关阅读:
    力扣leetcode 435. 无重叠区间
    C++中的快读和快写
    python安装wordcloud库报错
    python习题 随机密码生成 + 连续质数计算
    python 四位玫瑰数 + 100以内素数求和
    解决git add README.md 时报错 fatal: pathspec 'README.md' did not match any files
    洛谷P3817 小A的糖果 贪心思想
    多机部署之session共享解决方案-copy
    一点区块链资料-copy
    kafka集群搭建及结合springboot使用-copy
  • 原文地址:https://www.cnblogs.com/salam/p/1918994.html
Copyright © 2011-2022 走看看