0
Answer

BinaryFiles

hamzi AbuKhalla

hamzi AbuKhalla

15y
2.2k
1

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();