在VB中加载顺序文件

时间:2013-02-09 20:10:00

标签: 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() = 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.

当我运行程序时,我可以创建一个文件并保存数据,我可以使用对话框加载它,问题是我再次运行程序并尝试加载它。它只是不运行文件或加载它(记住我用这个程序创建了文件并保存)

如何让它发挥作用?

1 个答案:

答案 0 :(得分:1)

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

在运行程序的第一次和第二次之间退出Visual Studio。如果它工作,那么你知道你没有正确关闭文件。

new FileStream分配处设置断点并检查FileLocation的值。它是否与文件写入时相同?

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