Vb.net i';我正在尝试将文本文件加载到数组中。在vb中

Vb.net i';我正在尝试将文本文件加载到数组中。在vb中,vb.net,file-io,Vb.net,File Io,这就是我目前所拥有的 数组大小为(199,2) 该文件包含如下行:Canada,3402647812938494 美国,33777865345678 Sub LoadFromFile(filename As String) Dim Reader As StreamReader = File.OpenText(filename) Dim Currentline As String Dim lineArray() As String Do While Reader

这就是我目前所拥有的

数组大小为(199,2)

该文件包含如下行:Canada,3402647812938494 美国,33777865345678

Sub LoadFromFile(filename As String)

    Dim Reader As StreamReader = File.OpenText(filename)
    Dim Currentline As String
    Dim lineArray() As String

    Do While Reader.EndOfStream = False
        Currentline = Reader.ReadLine
        lineArray = Currentline.Split(","c)
    Loop

    Using sr As StreamReader = New StreamReader(filename)
        Do While sr.Peek() >= 0
            For Each c As Char In sr.ReadLine.Split
                Try
                    ValuesFromFile(y, x) = CStr(Integer.Parse(c))
                Catch ex As Exception 'i assume this is the only possible error, but we could be out of bounds due to assuming the actual size of the file/line... catch specific exceptions as necessary'
                End Try
                y += 1
            Next
            x += 1
            y = 0
        Loop
    End Using



    Reader.Close()
End Sub

为什么要读两遍文件?你有什么问题?你没有描述你发布的代码有什么问题。你在问什么具体问题?