streamReader将文本文件读取为无限

时间:2017-03-21 19:27:40

标签: vb.net console

我正在使用VB.net,我是读者使用流阅读器的文本文件。但问题是streamReader不知道它是在EOF上。 这是我的代码

Do Until SR.EndOfStream

        Currentline = SR.ReadLine()
        Do While Identifier <> Currentline
            recordsCount = recordsCount + 1
            'if it is second row 
            If recordsCount = 1 Then

                fields.Add("StatementDate", Currentline.Trim())
                Currentline = SR.ReadLine()
                Continue Do
            End If
            'if there is first row
            If recordsCount = 2 Then
                Console.WriteLine("Current record " & recordsCount)
                Dim secondRow As New List(Of String)

                secondRow.AddRange(Currentline.Trim().Split(New Char() {" ", "\t"}, StringSplitOptions.RemoveEmptyEntries))

                'account number
                AcctNum = secondRow.First()
                fields.Add("AccountNumber", AcctNum)
                fields.Add("PaymentDueDate", secondRow.ElementAt(2))
                fields.Add("PastDueAmt", secondRow.ElementAt(3))
                fields.Add("CurrentAmtDue", secondRow.ElementAt(4))
                fields.Add("MinPaymentDue", secondRow.ElementAt(5))
                fields.Add("NewBalance", secondRow.ElementAt(6))
                'moving to next record
                Currentline = SR.ReadLine()
            End If

            'if the mailing addres row
            If recordsCount = 3 Then
                Dim nextmatch As String
                addresCounter = addresCounter + 1
                Console.WriteLine("\n")
                Console.WriteLine("address counter is " & addresCounter)
                accountIdentifier = AcctNum
                nextmatch = Currentline
                '   while account number is not repeated
                Do While nextmatch <> accountIdentifier
                    'loop until end line of mailing address found
                    If (Currentline.Contains("HOME")) Then

                        'adding the last line of address
                        mailingAddressList.Add(Currentline.Substring(0, 53).Trim())
                        'adding the statement header to the list
                        statementWindowList.AddRange(Currentline.Substring(53, 26).Split(" "))
                        fields.Add("HOME", statementWindowList.ElementAt(0))
                        fields.Add("EQUITY", statementWindowList.ElementAt(1))
                        fields.Add("LINE", statementWindowList.ElementAt(2))
                        fields.Add("OF", statementWindowList.ElementAt(3))
                        fields.Add("CREDIT", statementWindowList.ElementAt(4))
                        Currentline = SR.ReadLine()
                        'if more address is pending than add it to the same list
                        If Not Currentline.Contains(accountIdentifier) Then
                            mailingAddressList.Add(Currentline.Trim())
                            Currentline = SR.ReadLine()
                        End If

                        statementReturnedDetails.AddRange(Currentline.Trim().Split(New Char() {" ", "\t"}, StringSplitOptions.RemoveEmptyEntries))
                        If statementReturnedDetails.Any() Then
                            fields.Add("CredtiLimit", statementReturnedDetails.ElementAt(3))
                            fields.Add("AvailableCredit", statementReturnedDetails.ElementAt(4))
                            fields.Add("Previous_Balance", statementReturnedDetails.ElementAt(6))
                            nextmatch = statementReturnedDetails.ElementAt(0)

                        End If
                        Continue Do

                    End If
                    'adding the mailing address
                    mailingAddressList.Add(Currentline.Trim())
                    'moving to the next row
                    Currentline = SR.ReadLine()
                    nextmatch = Currentline

                Loop

                addresCounter = 0
                Currentline = SR.ReadLine()

            End If

            'for body of the statement
            If recordsCount > 3 Then
                statementbody.Add(Currentline)
                Currentline = SR.ReadLine()
            End If



        Loop

    Loop

我只是想告诉小流一下它的EOF然后就出来了。但它仍然读到零。

0 个答案:

没有答案