• File Stream ReadWrite Access (VB 2005 Express/Vista)

    Home » Forums » Developers, developers, developers » DevOps Lounge » File Stream ReadWrite Access (VB 2005 Express/Vista)

    Author
    Topic
    #444562

    I am transitioning from VB 2 to VB2005 Express, so I’m spending a log of time with textbooks. I have a file containing one single string of text. I want to read the text, update it and re-write it. According to my textbook I can open the file in ReadWrite mode but I can not get it to work. Please consider the following code:
    Dim fsStream As FileStream
    Dim srReader As StreamReader
    Dim swWriter As StreamWriter
    Dim strWork As String

    fsStream = New FileStream(“C:MyTextFile”, FileMode.Open, FileAccess.ReadWrite)

    srReader = New StreamReader(fsStream)
    strWork = srReader.ReadLine()
    srReader.Close()

    swWriter = New StreamWriter(fsStream) <<< This statement abends with the message "Stream was not writeable"

    Now I know that I can write this as a separate Read block, close it all down, then write a separate Write block, but i'm trying to learn how FileAccess.ReadWrite works. Can someone please tell me where I'm going wrong?

    Thanks,

    John Littell

    Reply To: File Stream ReadWrite Access (VB 2005 Express/Vista)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: