111,126
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string m_path = @"c:\datafile3.dat";
int[,] m_array = { { 2, 3, }, { 4, 5 } };
write(m_path, m_array);
read(m_path);
}
public static void write(string strpath, int[,] array)
{
using (FileStream myarray = new FileStream(strpath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
BinaryWriter bw = new BinaryWriter(myarray);
foreach (int i in array)
{
bw.Write(i);
}
bw.Flush();
bw.Close();
myarray.Close();
Console.WriteLine("write succeed");
Console.ReadLine();
}
}
public static void read(string strpath)
{
using (FileStream m_fa = new FileStream(strpath, FileMode.Open, FileAccess.ReadWrite))
{
BinaryReader bs = new BinaryReader(m_fa);
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
{
Console.Write(bs.ReadInt32());
Console.ReadLine();
}
}
}
}
}