using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace filestream
{
class Program
{
static void Main(string[] args)
{
try
{
#region FileStream文件流
//写入
FileStream fileStream = new FileStream(@"d: est.txt", FileMode.OpenOrCreate);
fileStream.Position = fileStream.Length;
byte[] content = Encoding.UTF8.GetBytes("我爱我家");
fileStream.Write(content, 0, content.Length);
fileStream.Position = fileStream.Length;
content = Encoding.UTF8.GetBytes("45");
fileStream.Write(content, 0, content.Length);
fileStream.Close();
//读取
fileStream = new FileStream(@"d: est.txt", FileMode.Open);
content = new byte[fileStream.Length];
fileStream.Read(content, 0, content.Length);
Console.WriteLine(Encoding.UTF8.GetString(content));
#endregion
//#region MemoryStream内存流
//MemoryStream me = new MemoryStream();
//Console.WriteLine("初始分配的容量:" + me.Capacity + "初始使用量:" + me.Length);
//byte[] contents = Encoding.UTF8.GetBytes("我爱我家");
//me.Write(contents, 0, contents.Length);
//Console.WriteLine("初始分配的容量:" + me.Capacity + "初始使用量:" + me.Length);
//#endregion
FileStream mss = new FileStream(@"dkeygen.exe", FileMode.Open);
BinaryReader br = new BinaryReader(mss);
char cha;
int num;
double doub;
string str;
while (true)
{
cha = br.ReadChar();
num = br.ReadInt32();
doub = br.ReadDouble();
str = br.ReadString();
Console.WriteLine("{0},{1},{2},{2}", cha, num, doub, str);
}
}
catch (Exception)
{
throw;
}
}
}
}