2017-10-18 23 views
-1

我试图读取的文件位于bin \ debug文件中名为systemstate的文件中。我有一个文本文件调用该文件中的systemdetails和那里的一个文件叫产品和一个文件的产品叫P0包含文本文件的其余部分io.file.Readalllines适用于一个文件名但不适用于其他人也不会抛出无效文件名上的异常

在第一行的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]" 
+0

“剩余失败”是什么意思?如果他们没有抛出异常,他们做什么?返回一个null或空数组?跳过该方法而不继续? –

+0

@StevenDoggart当我在调试模式下遇到第一个失败的readalllines并且我跨过它时,系统停止调试并且程序显示正在运行 – adeel

+0

product.add部分在所有读取都不运行时出现 – adeel

回答

1

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

相关问题