首页 > 其他 > 详细

对象写入文件和从文件中重构到对象

时间:2016-12-05 23:33:58      阅读:202      评论:0      收藏:0      [点我收藏+]
                //将对象写入文件中
                Game game = new Game();
                game.Level = 2;
                game.Player = "Tom";
                FileStream fs = new FileStream(@"game.bak",FileMode.OpenOrCreate,FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(game.Player);
                sw.WriteLine(game.Level);
                sw.Flush();
                sw.Close();
               //将文件重构成对象
                Game game = new Game();
                FileStream fs = new FileStream(@"game.bak", FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);
                game.Player = sr.ReadLine();
                game.Leveal = sr.ReadLine();
                sr.Close();

 

对象写入文件和从文件中重构到对象

原文:http://www.cnblogs.com/zwnet/p/6135595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!