hamzi AbuKhalla

hamzi AbuKhalla

  • 1.4k
  • 198
  • 44.2k

BinaryFiles

Apr 28 2009 11:57 AM

hello there!
i want to save string to file in binary method with C#
it dosent work. 4 example i want to save the string "Hello World" to "myFile.bin" and if i edit this file with notepad i will get this result
???J†Yn?’F\$?i?e???¥\%??­­??§
anyone can help with code !!!
my code dosnt work

FileStream BinaryFile = new FileStream("c:\\test.dat", FileMode.Create, FileAccess.ReadWrite);
            BinaryWriter Writer = new BinaryWriter(BinaryFile);

            Writer.Write("hello world");
            Writer.Close();
   

            BinaryFile = new FileStream("C:\\test.dat", FileMode.Open , FileAccess.Read);
            BinaryReader  reader =  new BinaryReader (BinaryFile);
            Console.WriteLine(reader.ReadString());
           

            Console.ReadLine();