C#无法再流的结尾之外进行读取 代码已给出
string fileName = "MyNew.data"; //定义字符串变量存储文件名字符串 if (!(File.Exists(fileName))) { MessageBox.Show("当前文件不存在"); return; } string strData = ""; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); //以读取已有文件的方式创建FileStream的实例化对象 BinaryReader reader = new BinaryReader(fs); //实例化BinaryReader类 strData = reader.ReadString(); //调用BinaryReader类的ReadString方法 for (int i = 0; i < 200; i++) { if (i == 0) { strData += reader.ReadInt32().ToString(); //每次读取4个字节带符号的整数值,并转换为字符串类型 } else { strData += " || " + reader.ReadInt32().ToString(); } } textBox2.Text = strData; //读取的文件内容显示在textBox2上面 fs.Close(); //关闭文件流对象 reader.Close(); //关闭二进制文件读对象存储文件名字符串 }