最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
WP7独立存储IsolatedStorageFile读写文件实现程序
时间:2022-06-26 00:19:10 编辑:袖梨 来源:一聚教程网
| 代码如下 | 复制代码 |
| IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); //如果是复写文件,那么在写之前最好把文件删掉,不然如果这次写入的文件大小,小于文件本身的大小,那么之前文件的数据还是存在的,在读取的时候就会出问题. if (myIsolatedStorage.FileExists(filename) == true) { myIsolatedStorage.DeleteFile(filename); } using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(filename, FileMode.CreateNew)) { List foreach (var i in coll) { favlist.Add(i); } using (var str = new StreamWriter(stream)) { str.Write(JsonConvert.SerializeObject(favlist)); } } |
|
代码中的注释部分,一定要慎重.复写之前最好删掉文件,不然会因为数据不正确而导致读取的时候出错.而且这类错误很难排查.
然后是读文件的代码:
| 代码如下 | 复制代码 |
|
IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); |
|
相关文章
- gmail邮箱登录-网页版gmail官网入口 03-14
- 12123交管官网-网页版登录入口-交管12123官网登录 03-14
- 漫蛙漫画-漫蛙MANWA2官网入口 03-14
- jm天堂漫画-官网入口ios版下载 03-14
- ChatGpt官网入口2026最新地址-一键直达官网分享 03-14
- 七猫小说网页版入口-七猫小说网页版免费畅读 03-14