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

    三、源码下载

        点击这里下载示例源码

  • 相关阅读:
    [POI2013]BAJ-ytecomputer [动态规划]
    【2019.10.15】网课 Za
    【初赛】
    [NOI2014]魔法森林[最短路 spfa]
    【洛谷2019金秋营模拟赛1】
    【luogu1315】 观光公交[贪心]
    【luogu4450】收集邮票 [期望dp]
    [HAOI2012]高速公路 [线段树 期望]
    ALGO-185 Trash Removal
    精度计算——减法
  • 原文地址:https://www.cnblogs.com/salam/p/1918994.html
Copyright © 2011-2022 走看看