文件流操作代码
System.IO.Stream stream = Request.InputStream; stream.Position = 0; System.IO.Compression.GZipStream zipStream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress); System.IO.StreamReader sr = new System.IO.StreamReader(zipStream, System.Text.Encoding.UTF8); String tmp = sr.ReadToEnd(); sr.Close(); zipStream.Close(); stream.Close(); string path = AppDomain.CurrentDomain.BaseDirectory; //如果不存在,则创建目录 if (!System.IO.Directory.Exists(path + "Log/")) { System.IO.Directory.CreateDirectory(path + "Log/"); } System.IO.FileStream fs = new System.IO.FileStream(path + "\\Log/hotelStatelog" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", System.IO.FileMode.Append); System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(fs); streamWriter.BaseStream.Seek(0, System.IO.SeekOrigin.End); streamWriter.WriteLine(DateTime.Now.ToString() + " " + tmp); streamWriter.Flush(); streamWriter.Close(); fs.Close();
posted on 2015-03-05 15:58 Anthony.Zhao 阅读(202) 评论(0) 编辑 收藏 举报