DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: want to read a nested ArrayList from a text file.

  1. #1
    Join Date
    Aug 2007

    want to read a nested ArrayList from a text file.

    I have a nested java ArrayList in a text file. I need to read that ArrayList in a Java program, and work with it. The problem is, whenever I am reading the file, I could only read the ArrayList as a String. Can anyone please help me to read the List in the file, as the same list in the java program?

    Actually, I have created a java Arraylist in another program, and have copied the arraylist to a text file. The Arraylist is nested: (e.g. [a, b, [c, [d, e]]] ) Now, I need to read that ArrayList from the text in a java program and work with it. The problem I am facing is, I can read the ArrayList only as a string from the file. I am using :

    " FileReader fr = new FileReader ("javaList.txt");
    BufferedReader br = new BufferedReader (fr);"

    Now, converting that string to a similar nested Arraylist is proving to be difficult for me. I don't know how to do it.

    Thanks a lot!

  2. #2
    Join Date
    Mar 2004
    Was the arraylist written to file as a serialized object or just plain text? If plain text, then what structure was it written? Just reverse the method you used for writing to read it back in.

  3. #3
    Join Date
    Aug 2007
    Hi, i read a python List and converted it to a Java list in Jython. This is the code in Jython :


    p = listquote.LineParser() // read the python list from the file as a list.
    aList = p.feed(fileList)
    anotherJavaList= java.util.LinkedList(aJavaList)

    output = open('javaList.txt','w')
    print >> output, anotherJavaList

    Now, I need to read that List from javaList.txt into a Java program, and work with that.

  4. #4
    Join Date
    Mar 2004
    You may just have to save the list in a format you can easily parse so it can be recreated. You may want to consider saving the file in XML format.
    Just as an example:
    <container id="foo">
        <container id="stuff">
    <container id="bar">

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2005, 04:36 AM
  2. How to read all words in a text file
    By crazyguitarchik in forum Java
    Replies: 1
    Last Post: 11-30-2005, 09:12 PM
  3. Can a text file be read using ADO?
    By Ted Young in forum VB Classic
    Replies: 1
    Last Post: 08-21-2000, 09:47 PM
  4. Replies: 1
    Last Post: 05-03-2000, 03:38 AM
  5. Replies: 0
    Last Post: 04-17-2000, 01:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center