【发布时间】:2018-02-19 20:15:57
【问题描述】:
我无法让 Binary Reader 检测从“浏览文件夹”对话框中选择的文件。目的是读取目录中所有文件中的“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.
【问题讨论】:
-
BinaryReader采用Stream而不是文件路径stringmsdn.microsoft.com/en-us/library/… -
试试 :StreamReader reader = new StreamReader(file); BinaryReader NDSRead2 = new BinaryReader(reader);
-
您确定需要二进制阅读器而不是 StreamReader 吗? stackoverflow.com/questions/10353913/…
标签: c# folderbrowserdialog binaryreader