io.file.Readalllines适用于一个文件名,但不适用于任何其他文件名.它也不会对无效文件名引发异常



我试图读取的文件位于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]"

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

相关内容

最新更新