testing.res 文件大小为 240MB。我想读它。但是我在这一行得到了错误:
int v = br.ReadInt32();
EndOfStreamException 无法读取超出流末尾的内容
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
R();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void R()
{
using (var br = new System.IO.BinaryReader(File.Open(@"d:\testing.res", FileMode.Open)))
{
// 2.
// Position and length variables.
int pos = 0;
// 2A.
// Use BaseStream.
int length = (int)br.BaseStream.Length;
while (br.BaseStream.Position < length)
{
// 3.
// Read integer.
int v = br.ReadInt32();
textBox1.Text = v.ToString();
}
}
}
}
}
例外:
System.IO.EndOfStreamException was unhandled
Message=Unable to read beyond the end of the stream.
Source=mscorlib
StackTrace:
at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
at System.IO.BinaryReader.ReadInt32()
at WindowsFormsApplication1.Form1.R() in D:\C-Sharp\BinaryReader\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 41
at WindowsFormsApplication1.Form1..ctor() in D:\C-Sharp\BinaryReader\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 19
at WindowsFormsApplication1.Program.Main() in D:\C-Sharp\BinaryReader\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: