locked
how to write ArrayList to and read ArrayList from file

    Question

  • which one is better for doing this? streamreader/writer or binaryreader/writer. any conversion needed?

     

     

    thanks

     

     

    Saturday, January 19, 2008 6:57 PM

Answers

  •  

    Andy,

     

    I was wrong. A streamreader would be the best.

    Saturday, January 19, 2008 9:58 PM
  •  

     

    ok , i figure it out now, how to write 2D arraylist into file

    something like:

    ...

      Dim FS As New FileStream(arrayStorePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)
      Dim SW As New StreamWriter(FS)


      For Each currentitem As ArrayList In outterarray
       For Each item As String In innerarray
        SW.WriteLine(item)
       Next
      Next
      SW.Close()
      FS.Close()

    ...

     

    PS, still want to konw that:

    is there alternative way to write and read entire object into and from file?

    Sunday, January 20, 2008 9:12 AM

All replies

  •  

    System.IO.TextReader
    Saturday, January 19, 2008 7:23 PM
  •  

    don't understand that, can textwriter/reader write or read object directly?

    can any one explain more detail with example code, please?

     

    thanks

    Saturday, January 19, 2008 8:31 PM
  •  

    Andy,

     

    I was wrong. A streamreader would be the best.

    Saturday, January 19, 2008 9:58 PM
  • Hi

     

    i tried streamwriter. someting like:

    ...
    Dim FS As New FileStream(arrayStorePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)
      Dim SW As New StreamWriter(FS)


      For Each currentItem As String In CurrentArrayList
       SW.WriteLine(currentItem)
      Next

      SW.Close()
      FS.Close()

    ...

     

    the problem is, the system can not convert currentItem ( the object of friend class) into string, because the arraylist i created is 2D array. currentArrayList contains several inner arraylist, which is object of friend class, and each object includes its own lastname, firstname and DOB ext... the example code is really appreciated

     

     

    PS, is there alternative way to write and read entire object into and from file?

    Sunday, January 20, 2008 8:43 AM
  •  

     

    ok , i figure it out now, how to write 2D arraylist into file

    something like:

    ...

      Dim FS As New FileStream(arrayStorePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)
      Dim SW As New StreamWriter(FS)


      For Each currentitem As ArrayList In outterarray
       For Each item As String In innerarray
        SW.WriteLine(item)
       Next
      Next
      SW.Close()
      FS.Close()

    ...

     

    PS, still want to konw that:

    is there alternative way to write and read entire object into and from file?

    Sunday, January 20, 2008 9:12 AM
  •  

    I know nothing about the object as you haven't told me much about it. One time, a long time ago I wrote a toolbar and of course wanted to store the buttons but Buttons are not serializable. So I stored all of the descriptors of the buttons in a structure, stored the structures in a dictionary and they are serializable. Hence a tiny one of a kind database.

     

    I would say yes that it's possible to store almost anything when you stop and think about it.

     

     

    Sunday, January 20, 2008 2:35 PM