【WP之一】]独立存储
介绍:
提供一个磁盘存储空间,他是一种虚拟的文件系统,能存储小量的数据;在默认的情况下,它只能存储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之一】]独立存储的更多相关文章
- WP8 独立存储 总结3(应用设置)
•可在独立存储中使用ApplicationSettings对象•在独立存储中存储键/值对的Dictionary方式存储 •存储的对象将永久保存 在应用设置中保存数据 void saveString(s ...
- WP_从独立存储区读取缓存的图片
///<summary> /// 独立存储缓存的图片源 /// 用法:item.img = new StorageCachedImage(newUri(http://www.baidu ...
- Silverlight 独立存储(IsolatedStorageFile)
1.在Web中添加天气服务引用地址 http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 2.在Web中添加Wcf服务接口I ...
- Windows phone 之独立存储
独立存储命名空间的说明:
- win10的独立存储
win10的独立存储和win8的大致相同 Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.Appl ...
- 与众不同 windows phone (6) - Isolated Storage(独立存储)
原文:与众不同 windows phone (6) - Isolated Storage(独立存储) [索引页][源码下载] 与众不同 windows phone (6) - Isolated Sto ...
- Windows Phone 独立存储资源管理器工具
如何使用独立存储资源管理器工具 http://msdn.microsoft.com/zh-CN/library/hh286408(v=vs.92)C:\Program Files (x86)\Micr ...
- Windows Phone 独立存储查看器
1.为了查看我们存放在独立存储的数据,我们需要借助独立存储查看器. 2.简单介绍下,IsoStoreSpy 下载地址:http://download.csdn.net/download/lhb1097 ...
- Silverlight-管理独立存储(Isolated Storage)
Silverlight中的独立存储是其内部的可信任的可访问文件空间,在这里你可以使用Silverlight 随意的创建.读取.写入.删除目录和文件,它有一些类似于Cookie,但是它可以在客户端保存大 ...
- k8s StatefulSet控制器-独立存储
k8s-StatefulSet控制器-独立存储 1. StatefulSet控制器-独立存储 独享存储:StatefulSet的存储卷使用VolumeClaimTemplate创建,称为卷申请模板,当 ...
随机推荐
- 推荐一些android开发学习的资料
网址: 1:http://v.youku.com/v_show/id_XMTgwMTQ1MTgw.html 2:http://mars.apkbus.com/ 3:http://wenku.baidu ...
- UVa 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
- android中ListView_SimpleAdapter
1.首先看下main_activity.xml.其实里面就放了一个ListView. <LinearLayout xmlns:android="http://schemas.andro ...
- PHP内存消耗
由于变量占用的空间不一样,所以其消耗的内存大小也不一样,在PHP中我们可以通过使用“memory_get_usage”来获取当前PHP消耗的内存.但是根据操作系统.PHP版本以及PHP的运行方式可能输 ...
- Xcode7.0.1(ios9)的部分适配问题
今天更新了Xcode 7 正式版,App编译出现很多警告,在App运行的时候出现如下的提示......... the resource could not be loaded because the ...
- 10个你能参与并学习的Java开源项目
本文转载于:http://code.csdn.net/news/2822604 有很多备受关注的初创开源项目,下面列出十个项目是我觉得非常有趣的,涉及到的学习范围也很广.其中有些还在早期阶段,这对我们 ...
- 磁盘检验[转自vbird]
磁盘检验 由于系统在运行时谁也说不准啥时硬件或者是电源会有问题,所以『死机』可能是难免的情况(不管是硬件还是软件). 现在我们知道文件系统运行时会有硬盘与内存数据异步的状况发生,因此莫名其妙的死机非常 ...
- Linux perf tools
http://techblog.netflix.com/2015/08/netflix-at-velocity-2015-linux.html
- javaScript call 函数的用法说明
call 方法 请参阅 应用于:Function 对象 要求 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg2[, [,.ar ...
- page cache 与 page buffer 转
page cache 与 page buffer 标签: cachebuffer磁盘treelinux脚本 2012-05-07 20:47 2905人阅读 评论(0) 收藏 举报 分类: 内核编程 ...