介绍:

提供一个磁盘存储空间,他是一种虚拟的文件系统,能存储小量的数据;在默认的情况下,它只能存储1MB的文件。根据使用方式及功能的不同,独立存储空间又包含两部分:独立设置存储和独立文件存储。除非卸载应用,否则数据不会消失。

第一是通过库中的键/值对,叫做IsolatedStorageSettings(独立设置存储),第二是通过创建真实的文件和目录,叫做IsolatedStorageFile(独立文件存储)。

独立设置存储:
命名空间为:System.IO.IsolatedStorage;主要涉及System.IO.IsolatedStorage.IsolatedStorageSettings类。
常用操作:
//创建操作独立设置存储必须的IsolatedStorageSettings类的对象
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
//增
settings.Add(key,value);
//删
settings.Remove("kk");
//改
settings["kk"] = value;
//查
string kk = (string)settings["kk"]; //判断该键是否存在
settings.Contains("kk");
//清除
settings.Clear();
//最终都需要保存
settings.Save();

独立文件存储:

命名空间为:System.IO.IsolatedStorage;主要涉及System.IO.IsolatedStorage.IsolatedStorageFile类。实际上,IsolatedStorage.IsolatedStorageFile类是 FileStream类 的一个子类。

CreateDirectory()        创建一个新的独立存储文件夹 
         DeleteDirectory()        删除独立存储文件夹        
         CreateFile()                创建文件 
         DeleteFile()                删除文件                   
         GetFileNames()           得到文件名称集合 
         GetDirectoryName()    得到文件夹名称集合 
         OpenFile()                  打开文件 
         Remove()                  移除所有的文件和文件夹

常用操作:

...
using System.IO.IsolatedStorage;
using System.IO; namespace PhoneApp19
{
public partial class MainPage : PhoneApplicationPage
{
//为程序获取一个虚拟的本地存储
IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication();
// 构造函数
public MainPage()
{
InitializeComponent();
}
//写入数据
private void btnWrite_Click(object sender, RoutedEventArgs e)
{
string filePath = txbFilePath.Text.Trim();
string fileName = txbFileName.Text.Trim();
string fullFileName = System.IO.Path.Combine(filePath,fileName);
string content = txbContent.Text;
//判断文件夹是否存在,若不存在则创建
if (!storageFile.DirectoryExists(filePath))
{
storageFile.CreateDirectory(filePath);
}
//写入
using (StreamWriter writer = new StreamWriter(storageFile.OpenFile(fullFileName, FileMode.Append)))
{
writer.WriteLine(content);
}
}
//读取数据
private void btnRead_Click(object sender, RoutedEventArgs e)
{
string fullFilePath = txbFullFilePath.Text.Trim();
//判断文件是否存在
if (!storageFile.FileExists(fullFilePath))
{
txbReadContent.Text = "指定文件不存在";
return;
}
//读取
using (StreamReader reader = new StreamReader(storageFile.OpenFile(fullFilePath, FileMode.Open)))
{
txbReadContent.Text = reader.ReadToEnd();
}
} }
}

【WP之一】]独立存储的更多相关文章

  1. WP8 独立存储 总结3(应用设置)

    •可在独立存储中使用ApplicationSettings对象•在独立存储中存储键/值对的Dictionary方式存储 •存储的对象将永久保存 在应用设置中保存数据 void saveString(s ...

  2. WP_从独立存储区读取缓存的图片

      ///<summary> /// 独立存储缓存的图片源 /// 用法:item.img = new StorageCachedImage(newUri(http://www.baidu ...

  3. Silverlight 独立存储(IsolatedStorageFile)

    1.在Web中添加天气服务引用地址 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 2.在Web中添加Wcf服务接口I ...

  4. Windows phone 之独立存储

    独立存储命名空间的说明:

  5. win10的独立存储

    win10的独立存储和win8的大致相同 Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.Appl ...

  6. 与众不同 windows phone (6) - Isolated Storage(独立存储)

    原文:与众不同 windows phone (6) - Isolated Storage(独立存储) [索引页][源码下载] 与众不同 windows phone (6) - Isolated Sto ...

  7. Windows Phone 独立存储资源管理器工具

    如何使用独立存储资源管理器工具 http://msdn.microsoft.com/zh-CN/library/hh286408(v=vs.92)C:\Program Files (x86)\Micr ...

  8. Windows Phone 独立存储查看器

    1.为了查看我们存放在独立存储的数据,我们需要借助独立存储查看器. 2.简单介绍下,IsoStoreSpy 下载地址:http://download.csdn.net/download/lhb1097 ...

  9. Silverlight-管理独立存储(Isolated Storage)

    Silverlight中的独立存储是其内部的可信任的可访问文件空间,在这里你可以使用Silverlight 随意的创建.读取.写入.删除目录和文件,它有一些类似于Cookie,但是它可以在客户端保存大 ...

  10. k8s StatefulSet控制器-独立存储

    k8s-StatefulSet控制器-独立存储 1. StatefulSet控制器-独立存储 独享存储:StatefulSet的存储卷使用VolumeClaimTemplate创建,称为卷申请模板,当 ...

随机推荐

  1. 【渗透测试学习平台】 web for pentester -2.SQL注入

    Example 1 字符类型的注入,无过滤 http://192.168.91.139/sqli/example1.php?name=root http://192.168.91.139/sqli/e ...

  2. Java—面向对象—权限修饰符及思维导图

    课上老师所讲实例整理: package org.hanqi.pn0120; //汽车 public class Car { //颜色 private String yanse; //品牌 privat ...

  3. c语言开发手机通讯录

    // //  main.c //  手机通讯录 // //  Created by Kevin-Dfg on 16/4/19. //  Copyright © 2016年 Kevin-Dfg. All ...

  4. Linux驱动设计——字符杂项设备

    杂项设备 linux里面的misc杂项设备是主设备号为10的驱动设备,misc设备其实也就是特殊的字符设备,可自动生成设备节点. 定义头文件<linux/miscdevice.h>   杂 ...

  5. GDI+中GIF图片的显示

    某位网友曾经问过我GDI+中Gif图像显示的问题,一直没时间给你写,在此致歉.我把这篇文章送给他. 一.GIF格式介绍 1.概述 GIF(Graphics Interchange Format,图形交 ...

  6. Maximum number of WAL files in the pg_xlog directory (2)

    Jeff Janes: Hi, As part of our monitoring work for our customers, we stumbled upon an issue with our ...

  7. EDIUS和VEGAS哪个更好用

    随着数字化电视系统发展的步伐日趋加快,计算机技术逐步渗透到广播电视的各个领域,非线性编辑系统在广播电视行业内占据越来越重要的地位,而且正向多样化 发展.因此,非线性编辑技术的操作应用对于编辑人员有着非 ...

  8. 怎么解决ABBYY找不到_FRBatch.pac的问题

    ABBYY Screenshot Reader是ABBYY FineReader 12OCR文字识别软件中自带的一个插件,通常情况下与ABBYY FineReader 12一起安装到计算机中,它是一款 ...

  9. ABBYY PDF Transformer+ Pro支持全世界189种语言

    ABBYY PDF Transformer+ Pro版支持189种语言,包括我们人类的自然语言.人造语言以及正式语言.受支持的语言可能会因产品的版本不同而各异.本文具体列举了所有ABBYY PDF T ...

  10. 【转】图解CSS的padding,margin,border属性(详细介绍及举例说明)

    W3C组织建议把所有网页上的对像都放在一个盒(box)中,设计师可以通过创建定义来控制这个盒的属性,这些对像包括段落.列表.标题.图片以及层.盒模型主要定义四个区域:内容(content).边框距(p ...