1.基于流的文件操作
2.FileStream类的部分属性和方法
3.与FileStream类相关的枚举
4.程序代码
string fileName=@"D:\filestream.data";
if(!File.Exists(fileName))
{
FileInfo myFile=new FileInfo(fileName);
FileStream fileStream = myFile.OpenWrite();
byte[] datas = { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109 };
fileStream.Write(datas,0, datas.Length);
Console.WriteLine("文件已写入");
fileStream.Close();
}
else
{
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
byte[] datas = new byte[fileStream.Length];
fileStream.Read(datas,0, datas.Length);
Console.WriteLine("读取数据:");
foreach (byte data in datas)
{
Console.WriteLine(data);
}
fileStream.Close();
}