FileStream example

quwiltw

Well-known member
Joined
Sep 18, 2001
Messages
486
Location
Washington, D.C.
anyone have a code snippet using the filestream class? the documentation says "In the following example,..." and there is no example following.
 
Code:
    Public Function SaveToFile(ByVal saveThis As String) As Boolean
        Try
            Dim sb As New FileStream(Application.StartupPath & "\test.txt", FileMode.OpenOrCreate)
            Dim sw As New StreamWriter(sb)

            sw.Write(saveThis)
            sw.Close()

            Return True
        Catch
            Return False
        End Try
    End Function

    Private Function OpenFile() As Boolean
        Dim sr As StreamReader
        sr = File.OpenText(Application.StartupPath & "\test.txt")

        Dim strItems As String
        loop through the text file
        While sr.Peek <> -1
            strItems = sr.ReadLine()

            using [b]strItems[/b] add eachline to something here 
        End While
        sr.Close()

        Return True file was there...with no errors
    End Function
 
Thanks Robby, I was hoping to see an example that used BeginRead/Write and EndRead/Write to reduce the need to load the entire file into memory in order to read it. For example, if you had a B+Tree and knew the size of every node and want to only load one specific subtree into memory and not the entire file.
 
Back
Top