2017-10-18 54 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幫助我檢測到異常

相關問題