Windows Phone 独立存储之IsolatedStorageFile
2012-05-22 08:26
495 查看
该类使独立存储的虚拟文件系统抽象化。IsolatedStorageFile对象对应于特定的独立存储范围,在该范围中存在由 IsolatedStorageFileStream对象表示的文件。应用程序可以使用独立存储将数据保存在文件系统中这些数据自己的独立部分,而不必在文件系统中指定特定的路径。
虚拟文件系统的根位于物理文件系统上经过模糊处理的每用户文件夹中。由主机提供的每个唯一标识符都映射为不同的根,该根为每个应用程序提供它自己的虚拟文件系统。应用程序不能从它自己的文件系统导航到另一个文件系统中。
因为独立存储区在特定程序集的范围内,所以其他大多数托管代码都不能访问您的代码的数据(高度受信任的托管代码和管理工具可以从其他程序集访问存储区)。非托管代码可以访问任何独立存储区。
1.获取独立存储IsolatedStorageFile对象
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
2.创建目录
myIsolatedStorage.CreateDirectory(path);
3.创建文件
myIsolatedStorage.CreateFile(path);
注意:创建文件所在文件夹不存在时,无法创建成功。
4.判断目录是否存在
bool isExists = myIsolatedStorage.DirectoryExists(path);
5.判断文件是否存在
bool isExists = myIsolatedStorage.FileExists(path);
6.删除文件
myIsolatedStorage.DeleteFile(path);
7.删除目录(需要递归实现)
View
Code
8.复杂文件
myIsolatedStorage.CopyFile(srcFilename/*源文件*/, dstFilename/*目标文件*/, overwrite/*是否覆盖*/);
9.读文件
View
Code
10.写文件
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(path,
fMode, myIsolatedStorage))
{
fileStream.Write(data, 0, size);
}
11.获取文件创建的日期
DateTimeOffset offset = myIsolatedStorage.GetCreationTime(path);
DateTime creatDate = offset.DateTime;
相关文章推荐
- Windows Phone 独立存储之IsolatedStorageFile
- Windows Phone 独立存储之IsolatedStorageSettings
- 独立存储, windows phone IsolatedStorageFile
- Windows Phone 独立存储之IsolatedStorageSettings
- Windows Phone开发之路(18) 独立存储
- Windows Phone的本地存储——IsolatedStorageSettings
- Windows Phone的本地存储——IsolatedStorageFile
- windows phone:独立存储
- windows phone 独立存储空间的操作 (2)
- Windows Phone 7 独立存储Isolated Storage
- Windows Phone页面导航和独立存储开发总结
- Windows Phone页面导航和独立存储开发总结
- Windows Phone的本地存储——IsolatedStorageSettings
- Windows Phone 7独立存储空间IsolatedStorage
- Windows Phone 7的本地存储——IsolatedStorageSettings
- Windows Phone 7 独立存储Isolated Storage
- Windows Phone 8的独立存储文件系统
- Windows Phone 7 独立存储使用XML文件来存储信息
- 独立存储 – 比你想的更简单 Isolated Storage – Might Be Easier Than You Think [by Jesse Liberty]
- Windows phone 7中,把页面数据存为长期存储(非IsolatedStorageFile),而是用IsolatedStorageSettings