Stream Reader and Writer for bigginers

  • Thread starter Thread starter boskomihic
  • Start date Start date
Here is one example of using Stream Reader

Code:
   Private Function ReadIniFile() As ArrayList
      ****************************************
      * Read the Ini File into an Array List *
      ****************************************
      Dim srIniFile As System.IO.StreamReader
      Dim strFilePath As String
      Dim alFile As ArrayList = New ArrayList()
      Dim strRec As String
      Try
         mintTotal = 0
         strFilePath = Path.ChangeExtension([Assembly].GetExecutingAssembly.Location, "ini")
         srIniFile = System.IO.File.OpenText(strFilePath)

         *******************************
         * Read the File               *
         *******************************
         Do
            strRec = srIniFile.ReadLine()
            If strRec <> Nothing Then
               alFile.Add(strRec)
               mintTotal += 1
            End If
         Loop Until strRec = Nothing
         Return alFile

      Catch ex As Exception
         moErr.LogError(ex)
      Finally
         If Not srIniFile Is Nothing Then
            srIniFile.Close()
         End If
      End Try

   End Function
 
Last edited by a moderator:
Back
Top