标签:stream def write set turn object datetime 读写 path
//写入txt using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) { LogCont log = new LogCont { LogId = LogId, CurTime = DateTime.Now }; byte[] LogContent = Encoding.Default.GetBytes(JsonConvert.SerializeObject(log)); fs.SetLength(0); fs.Write(LogContent, 0, LogContent.Length); fs.Flush(); } //读取txt using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { fs.Seek(0, SeekOrigin.Begin); var btlength = fs.Length; byte[] bt = new byte[btlength]; int r = fs.Read(bt, 0, bt.Length); string ret = Encoding.Default.GetString(bt); LogCont fRet = JsonConvert.DeserializeObject<LogCont>(ret); return fRet; }
标签:stream def write set turn object datetime 读写 path
原文地址:http://www.cnblogs.com/DONET-LC/p/7976439.html