-
want to read a nested ArrayList from a text file.
Hi,
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!
-
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.
-
Hi, i read a python List and converted it to a Java list in Jython. This is the code in Jython :
input=open("pythonList.txt",'r')
fileList=input.readline()
input.close()
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
output.close()
Now, I need to read that List from javaList.txt into a Java program, and work with that.
Thanks!
-
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:
Code:
<container id="foo">
<item>thing1</item>
<item>thing2</item>
<container id="stuff">
<item>stuff</item>
</container>
</container>
<container id="bar">
<item>thing1</item>
</container>
Similar Threads
-
By sarasahg in forum Java
Replies: 1
Last Post: 12-13-2005, 03:36 AM
-
By crazyguitarchik in forum Java
Replies: 1
Last Post: 11-30-2005, 08:12 PM
-
By Ted Young in forum VB Classic
Replies: 1
Last Post: 08-21-2000, 09:47 PM
-
By Gabriele in forum Java
Replies: 1
Last Post: 05-03-2000, 03:38 AM
-
By deborah in forum authorevents.kurata
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks