介绍:

提供一个磁盘存储空间,他是一种虚拟的文件系统,能存储小量的数据;在默认的情况下,它只能存储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. CSS+DIV常用命名

    常用的符合CSS+DIV规则的命名 页头:header 登录条:loginBar 标志:logo 侧栏:sideBar 广告:banner 导航:nav 子导航:subNav 菜单:menu 子菜单: ...

  2. 增加mvc:resources后访问不了注解配置的controller的问题

    刚开始没有配置mvc:resourcescontroller能够正确访问,但是由于web.xml使用/拦截了所有的请求,所以静态资源访问不上增加mvc:resources之后,静态资源是能访问上了,但 ...

  3. 关于获取目录的N种方法 的汇总

    前段时间在Global.asax.cs中的Session_End中使用Server.MapPath() 出现"服务器操作在此上下文中不可用"异常. 网络上给出的解决方案:Syste ...

  4. JavaWeb学习记录(二十三)——文件上传与下载

    一.导入jar包

  5. URAL 1056 Computer Net(最短路)

    Computer Net Time limit: 2.0 secondMemory limit: 64 MB Background Computer net is created by consecu ...

  6. matlab 相关代码记录

    1. 判断是否存在指定的video_name, 若不存在,则在给定save_path下,新建一个video_name文件夹: 1 sec_path = [save_path, video_name, ...

  7. 动态链接库中函数的地址确定---PLT和GOT [转]

    前面写过动态链接库 延迟绑定的一篇博文,那篇文章我非常喜欢,但是当时刚搞清楚,自己写的比较凌乱,我最近学习了Ulrich Drepper的How to write share library,学习了几 ...

  8. Html-双斜杠//开头的URL(依赖协议的URL)

    今天看京东HTTPS,发现链接都是这种 <a href="//chaoshi.jd.com">京东超市</a> URL是以双斜杠"//" ...

  9. Linux-某电商网站流量劫持案例分析与思考

    [前言] 自腾讯与京东建立了战略合作关系之后,笔者网上购物就首选京东了.某天在家里访问京东首页的时候突然吃惊地发现浏览器突然跳到了第三方网站再回到京东,心里第一个反应就是中木马了. 竟然有这样的事,一 ...

  10. Android 程式开发:(十三)特殊碎片 —— 13.2 DialogFragment

    Android 程式开发:(十三)特殊碎片 —— 13.2 DialogFragment 原文地址 我们也可以创建另外一种碎片——DialogFragment.顾名思义,DialogFragment就 ...