【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创建,称为卷申请模板,当 ...
随机推荐
- fedora22多媒体编码
sudo dnf install gstreamer-plugins-bad gstreamer-plugins-bad-free-extras gstreamer-plugins-ugly gstr ...
- oracle锁机制
1 前言 数据库大并发操作要考虑死锁和锁的性能问题.看到网上大多语焉不详(尤其更新锁),所以这里做个简明解释,为下面描述方便,这里用T1代表一个数据 库执行请求,T2代表另一个请求,也可以理解为T1为 ...
- HTML5里autofocus属性
转载:http://www.webhek.com/html5-autofocus/ HTML5给我们带来了一大堆神奇的东西.以前需要用JavaScript和Flash完成的任务,例如表单校验,INPU ...
- MySQL中日期与字符串相互转换,并进行日期比较查询
技术交流群:233513714 1.日期无需转换查询(日期在数据库中的类型为字符串) select * from day where dateTime > '2016-03-15' 2.使用da ...
- SysTick 定时器的使用
SysTick是STM32中的一个24位的定时器. Cortex‐M3处理器内部包含了一个简单的定时器.因为所有的CM3芯片都带有这个定时器,软件在不同 CM3器件间的移植工作得以化简.该定时器的时钟 ...
- java基础之:匿名内部类应用例子一
一:接口 package com.yeepay.sxf.testclassforinner; /** * 回调接口. * @author shangxiaofei * */ public interf ...
- Python 基本语法1
Python 基础语法(一) Python的特点 1. 简单 Python是一种代表简单思想的语言. 2. 易学 Python有极其简单的语法. 3. 免费.开源 Python是FLOSS(自由/开放 ...
- Android sdk 镜像服务器资源
大连东软信息学院镜像服务器地址:- http://mirrors.neusoft.edu.cn 端口:80北京化工大学镜像服务器地址:- IPv4: http://ubuntu.buct.edu.cn ...
- 图片Exif信息
Exif文件格式简述链接:https://www.zhihu.com/question/23727439/answer/25467748 可交换图像文件常被简称为Exif(Exchangeable i ...
- ABBYY FineReader出现错误和警告提示的解决办法
识别结果的质量取决于多种因素,这些因素包括原始文档的质量.结构布局和文档导出参数等.在使用ABBYY FineReader Pro for Mac OCR文字识别软件处理文档的各个阶段,应用程序均可能 ...