日期:2014-05-17 浏览次数:20839 次
static void Main(string[] args)
{
//写入数字
string filePath;
Console.WriteLine("请输入需要创建的二进制文件路径(包括文件名)");
filePath = Console.ReadLine();
FileStream fileStream = new FileStream(filePath, FileMode.Create);
BinaryWriter writer = new BinaryWriter(fileStream);
for (int index = 0; index < 20; index++)
{
writer.Write(index);
}
Console.WriteLine("写入完毕");
writer.Close();
fileStream.Close();
}
static void Main(string[] args)
{
//读入数据
Console.WriteLine("请输入文件名:");
string filePath = Console.ReadLine();
if (!File.Exists(filePath))
{
Console.WriteLine("文件不存在。");
}
else
{
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fileStream);
try
{
while (true)
{
Console.WriteLine(reader.ReadInt16());