【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创建,称为卷申请模板,当 ...
随机推荐
- List-ApI及详解
1.API : add(Object o) remove(Object o) clear() indexOf(Object o) get(int i) size() iterator() isEmpt ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- Android ADT初始化失败
在android的官网上买下载android的adt完了,进行解压之后,开始点击 eclipse.exe,果然给了我一个惊喜,那就是 [ Failed to create the Java Virtu ...
- Eclipse反编译插件jad安装
下载jadClipse地址: 链接: http://pan.baidu.com/s/1kTN4TPd 提取码: 3fvd 将net.sf.jadclipse_3.3.0.jar拷贝到eclipse的 ...
- C++@类对象和类指针的区别(转)
原文地址不详 如下程序: #include <iostream> #include <string> using namespace std; class Student { ...
- 黑马程序员——JAVA基础之简述 类的封装
------- android培训.java培训.期待与您交流! ---------- 类的封装(Encapsulation) 封装:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 封装优 ...
- Twsited异步网络框架
Twisted是一个事件驱动的网络框架,其中包含了诸多功能,例如:网络协议.线程.数据库管理.网络操作.电子邮件等. Twisted介绍:http://blog.csdn.net/hanhuili/a ...
- linux下shell显示-bash-4.1#不显示路径解决方法
在linux shell中不显示路径了,显示为-bash-4.1#用起来很不方便. 如何改为显示路径的shell呢? 步骤如下: vim ~/.bash_profile (不用管.bash_profi ...
- Nginx-/etc/sysctl.conf 参数解释
来自<深入理解Nginx模块开发与架构解析> P9 #表示进程(例如一个worker进程)可能同时打开的最大句柄数,直接限制最大并发连接数 fs. #1代表允许将状态为TIME-WAIT状 ...
- python之os模块
#!/usr/bin/env python3# _*_ coding:utf-8 _*_ import os os.getcwd()#os.chdir('path')print(os.curdir)p ...