BinaryWriter 的简单问题,谁帮忙看下
class Program{
/// <summary>
/// 写入文件
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Console.WriteLine("请输入文件名:");
string filename = Console.ReadLine();
FileStream fs;//声明FileStream对象
try
{
fs = new FileStream(filename, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write('a');
bw.Write("liuxiaoxiaoying");
bw.Write(123456);
bw.Write(456.789);
Console.WriteLine("成功写入");
bw.Close();
fs.Close();
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
}
但写入进去的只有字符,和字符串,数字进去后是乱码,但书上写的是可以写入数字