본문 바로가기

Tip !!!/C# tip

C# 2진 파일 입출력 BinaryFile

static void Main(string[] args)
 {
            BinaryWriter bw = new BinaryWriter(new FileStream("binary_test.txt",  FileMode.Create))
            bw.Write(32);
            bw.Write(3.14f);
            bw.Write("한글");

            bw.Close();


            // BinaryReader br = new BinaryReader(new FileStream("binary_test.txt", FileMode.Open)))
            BinaryReader br = new BinaryReader( File.Open("binary_test.txt",FileMode.Open))
            int i=br.ReadInt32();
            float f=br.ReadSingle();
            string s=br.ReadString();
            Console.WriteLine("{0} {1} {2}",i,f,s); 

            br.Close();

   }