最新下载
热门教程
- 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(); |
相关文章
- 《弓箭传说2》新手玩法介绍 01-16
- 《地下城与勇士:起源》断桥烟雨多买多送活动内容一览 01-16
- 《差不多高手》醉拳龙技能特点分享 01-16
- 《鬼谷八荒》毕方尾羽解除限制道具推荐 01-16
- 《地下城与勇士:起源》阿拉德首次迎新春活动内容一览 01-16
- 《差不多高手》情圣技能特点分享 01-16