我正在读取一个二进制文件,并在等待发生的事情时,我注意到该程序没有做任何事情。程序似乎不想读取文件
它似乎被卡在某个执行点。我在一些打印语句中添加了控制台,并且可以看到它达到某个特定点......但似乎并不想继续。这是第一对夫妇的代码行:
private BinaryReader inFile;
public void Parser(string path)
{
byte[] newBytes;
newBytes = File.ReadAllBytes(path);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(newBytes, 0, newBytes.Length);
inFile = new BinaryReader(ms);
inFile.BaseStream.Seek(0, SeekOrigin.Begin);
}
}
public void ParseFile()
{
Console.WriteLine("parsing");
Console.WriteLine("get size to read"); // prints this out
int sizeToRead = inFile.ReadInt32();
Console.WriteLine("Size: {0}", sizeToRead); // doesn't print this out
Console.WriteLine("Done"); // end file processing
}
当我注释掉读取,它工作正常。我将的内容转储到一个新文件中,它与原始文件相同,所以它应该是一个有效的流。
我不知道如何继续调试此问题。任何人遇到类似的问题?
编辑:对不起,我发布了不同的方法和零件。下面是整个方法
什么是'inFile'? – CodingGorilla
Yep同意@CodingGorilla将需要知道'inFile'是什么,并且可以包含代码吗? –
对不起,它只是一个'BinaryReader' – MxyL