Vb.net 在VB中加载顺序文件

Vb.net 在VB中加载顺序文件,vb.net,file,Vb.net,File,几年前我写了一个vb程序,现在我又开始使用vb了,我遇到了一个“障碍”。使用顺序文件。我正试图通过“文件”对话框将文件加载到vb程序中 注意:我使用的是结构 Dim FileDialog as new openFileDialog Dim MyStream as Stream = nothing Dim FileLocation as string 'this is to save the file location if( FileDialog.ShowDialog() = DialogRe

几年前我写了一个vb程序,现在我又开始使用vb了,我遇到了一个“障碍”。使用顺序文件。我正试图通过“文件”对话框将文件加载到vb程序中

注意:我使用的是结构

Dim FileDialog as new openFileDialog
Dim MyStream as Stream = nothing
Dim FileLocation as string  'this is to save the file location
if( FileDialog.ShowDialog() = DialogResults.OK)Then
FS = new FileStream(FileLocation, FileMode.open, fileaccess.Read)
BF = new BinaryFromatter

While FS.Position < FS.Length 
   Dim temp as unit
    ...'Please note that this is where the file reads the structures data.It is to much code to write in.
Dim FileDialog作为新的openFileDialog
将MyStream设置为流=无
Dim FileLocation as string'用于保存文件位置
如果(FileDialog.ShowDialog()=DialogResults.OK),则
FS=新文件流(FileLocation、FileMode.open、fileaccess.Read)
BF=新的二进制Fromatter
而FS.位置
当我运行程序时,我可以创建一个文件并将其与数据一起保存在中,我可以使用对话框加载它,问题是当我再次运行程序并尝试加载它时。它只是无法运行或加载文件(记得我用这个程序创建了文件并保存了它)


如何使其工作?

确保在第一次写入和读取数据后关闭了文件,并确保使用了正确的路径(
FileLocation

在第一次和第二次运行程序之间退出Visual Studio。如果成功,那么您就知道没有正确关闭文件

newfilestream
赋值处设置断点,并检查
FileLocation
的值。是否与文件写入时相同


检查错误消息(如果有),看看是否有任何提示。

如何或何时设置变量
FileLocation
?您忘记关闭文件,现在它被锁定了?