Why does this code not write my string to the file:
string file = "Myfile.txt";
MemoryStream ms = new MemoryStream();
void writeToFile(string text)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
byte[] barr = encoding.GetBytes(text);
ms.Write(barr, 0, barr.Length);
using (FileStream fs = new FileStream(file, FileMode.OpenOrCreate))
{
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(ms.ToArray());
}
}
}
static void Main(string[] args)
{
Program p = new Program();
p.writeToFile("Tony Test");
Console.ReadLine();
}