Storing an object info

F

Firewalker

Hello guys,
I am trying to create a linked list where its nodes are StringBuffer
object. The thing that I wan to store this linked list somehow so that when
I reopen the java progra, it can loads the linked list again.
I had a method in my mind which is to store an object in the file and read
it back again.
The thing that I dont know how to do it, Can anyone point me to the righ
direction?
Or if you have a different effective method, would you please give me some
help?
Thanks alot for your help
 
M

Murray

Firewalker said:
Hello guys,
I am trying to create a linked list where its nodes are StringBuffer
object. The thing that I wan to store this linked list somehow so that when
I reopen the java progra, it can loads the linked list again.
I had a method in my mind which is to store an object in the file and read
it back again.
The thing that I dont know how to do it, Can anyone point me to the righ
direction?
Or if you have a different effective method, would you please give me some
help?
Thanks alot for your help

If performance isn't critical, you could Serialize the object and write it
to a file using ObjectOutputStream. There are many serialization tutorials
out there, try here for starters (random Google result):
http://www.acm.org/crossroads/xrds4-2/serial.html

I mention performance because often serialization of objects isn't terribly
efficient compared to more specific saving strategies. There's overhead of
saving information about the class that is neede to regenerate the object.
There are also some gotchas, e.g. different versions of class files. But in
most cases performance isn't a problem and it's the easiest solution.
 
F

Firewalker

Thank you for your reply, but isn't StringBuffer and LinkedList already
serialized objects??!
Also, performance is not an issue here.Btw, does this work in survletes?
This is the main reason for saving the object because after shutting tomcat,
I want the information to be kept when I restart tomcat again.

Thanks again for your help
 
M

Murray

Thank you for your reply, but isn't StringBuffer and LinkedList already
serialized objects??!

No, they are Serializable <-- note the "able" on the end. This means you
are able to serialize them to a file/other storage medium if you want to. If
you read the link in my other post, you'll see how to write serializable
objects to a file.
Btw, does this work in survletes?
This is the main reason for saving the object because after shutting tomcat,
I want the information to be kept when I restart tomcat again.

Well it has nothing to do with servlets, it's just plain old Java code which
will work no matter what kind of program you're dealing with. Can you post
some code so we can see exactly what you're trying to do? There may well be
a better solution ...
 
L

Liz

Murray said:
No, they are Serializable <-- note the "able" on the end. This means you
are able to serialize them to a file/other storage medium if you want to. If
you read the link in my other post, you'll see how to write serializable
objects to a file.


Well it has nothing to do with servlets, it's just plain old Java code which
will work no matter what kind of program you're dealing with. Can you post
some code so we can see exactly what you're trying to do? There may well be
a better solution ...
Nothing says it has to be stored on disk in any particular way. Why
not just use a database table and put the info for each node into a tuple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top