C# - 浏览文件夹和二进制文件 Reader

C# - Browse Folder and Binary Reader

我很难让二进制 Reader 检测从 "Browse for Folder" 对话中选择的文件。目的是读取目录中所有文件的 "X" 位置并将该数据保存到 TXT 文件。我尝试了各种方法,但似乎无法理解...我遇到问题的行是:

BinaryReader NDSRead2 = new BinaryReader(file)

我用来替换 (file) 的任何内容都会引发错误。在我的代码中的那一行和其他地方尝试了各种方法,但似乎无法得到它。我的代码在下面列出。

 /// OPEN FOLDER DIALOGUE      
        FolderBrowserDialog fbd = new FolderBrowserDialog();
        fbd.Description = "Select a folder";
        fbd.ShowNewFolderButton = false;
        if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
           /// THIS NEXT CHUNK OF CODE SETS UP WHERE THE TXT FILE WILL BE SAVED, IN THE SELECTED DIRECTORY.
            string brlTextLoc = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            DirectoryInfo dir1 = new DirectoryInfo(fbd.SelectedPath);
           txtBRLSave = new System.IO.StreamWriter(fbd.SelectedPath + "BuildRomList.TXT", true);

            txtBRLSave.WriteLine("Build Rom List");
            txtBRLSave.WriteLine("Using The Rom Assistant v0.57");
            txtBRLSave.WriteLine();


          /// THE LOOP FOR EACH FILE TO BE READ IN FOLDER BEGINS.
            FileInfo[] files = dir1.GetFiles();
            System.IO.StreamWriter txtBRLSave;
            foreach (string file in Directory.EnumerateFiles(fbd.SelectedPath, "*.EXT"))
            {

                BinaryReader NDSRead2 = new BinaryReader(file);

            /// THE ISSUE I HAVE IS WITH "(FILE)" ABOVE... IT KEEPS GETTING FLAGGED IN RED NO MATTER WHAT I PUT IN THERE.

           /// BELOW CONTINUES THE BR CODE, AND TXT SAVING CODE, WHICH ISN'T NEEDED FOR THIS QUESTION AS I KNOW IT WORKS.

按如下方式将字符串传递到流中

foreach(string file in Directory.EnumerateFiles(...
{
    using(var stream = new FileStream(file, FileMode.Open))
    using(var NDSRead2 = new BinaryReader(stream))
    {
       // do you stuff
    }
}