-1

我试图读取的文件位于 bin\debug 文件中名为 systemstate 的文件中。我在该文件中有一个名为 systemdetails 的文本文件,其中有一个名为 Products 的文件和一个名为 P0 的产品文件,其中包含其余的文本文件

在下面的代码行中,第一个 readalllines 有效,其余的都失败了,没有引发任何异常,程序继续运行,就好像什么都没发生一样。

在 form1.vb 文件中

    Public Sub init()
    If start Then
        productcount = Int(IO.File.ReadAllLines(filestoreloc + systemfile)(0).Split()(1))
        For i As Integer = 0 To productcount
            Dim id As String = Str(i)

            Dim det As String() = IO.File.ReadAllLines(filestoreloc + Product.location + "P" + id + Product.detailsfile)
            Dim desc As String() = IO.File.ReadAllLines(filestoreloc + Product.location + "P" + id + Product.descriptionfile)
            Dim rev As String() = IO.File.ReadAllLines(filestoreloc + Product.location + "P" + id + Product.reviewfile)

            products.Add(New Product(det, desc, extractRecords(rev, Product.revstartmark, Product.revendmark)))
        Next
        start = False
    End If
End Sub

此方法从 Form1_load 方法调用

这些是上面代码中使用的变量:

在 form1.vb 文件中

Property filestoreloc As String = "systemstate\"

Property systemfile As String = "systemdetails.txt"

Property productcount As Integer

Property start As Boolean = True

在 product.vb 文件中

Public Shared Property location As String = "Products\"
Public Shared Property detailsfile As String = "\details.txt"
Public Shared Property descriptionfile As String = "\description.txt"
Public Shared Property reviewfile As String = "\reviews.txt"

Public Shared Property revstartmark As String = "[REVIEWSTART]"
Public Shared Property revendmark As String = "[REVIEWEND]"
4

1 回答 1

1

没有出现异常。这个异常是因为找不到目录,因为当我将 id 转换为字符串时,有一个前导空格 @StevenDoggart 帮助我检测到异常

于 2017-10-18T14:53:27.810 回答