照著課本練習key in
using System;
using System.IO;
using System.IO.Compression;
using System.IO.MemoryMappedFiles;
using System.Net.Http.Headers;
using System.Numerics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
MemoryMappedFile file = MemoryMappedFile.CreateNew("test", 200L);
using(var mvstream=file.CreateViewStream())
{
using(StreamWriter writer=new StreamWriter(mvstream))
{
writer.WriteLine("hello 1st");
writer.WriteLine("hello 2th");
}
}
using(MemoryMappedFile mfile=MemoryMappedFile.OpenExisting("test"))
{
using (var vstream=mfile.CreateViewStream())
{
using (StreamReader resder = new StreamReader(vstream))
{
string str = resder.ReadToEnd();
Console.WriteLine(str);
}
}
}
using (MemoryMappedFile mmfile = MemoryMappedFile.CreateFromFile("map.data", FileMode.OpenOrCreate, "udemo", 100L))
{
using (var vstream = mmfile.CreateViewStream())
{
using (BinaryWriter writer = new BinaryWriter(vstream))
{
writer.Write(150);
writer.Write(1.17f);
writer.Write(96000L);
writer.Write(13.965d);
}
}
}
using(FileStream stream=File.OpenRead("map.data"))
{
Console.WriteLine($"file size:{stream.Length}");
using(BinaryReader reader=new BinaryReader(stream))
{
int v1 = reader.ReadInt32();
float v2 = reader.ReadSingle();
long v3 = reader.ReadInt64();
double v4 = reader.ReadDouble();
Console.WriteLine($"AAA:{v1} {v2} {v3} {v4}");
}
}
}
}
}
沒有留言:
張貼留言