saving a vector to file

I wish to be able to save a vector to a file, so that when i start the java application again, i will be able to load the file back into the vector, and view all the data from the last session.

therefore, i want the code for saving a vector to file, and then loading the file back into a vector.

thanks

Gary

[332 byte] By [garyfitz123a] at [2007-11-27 2:19:12]
# 1
http://java.sun.com/docs/books/tutorial/essential/io/
CaptainMorgan08a at 2007-7-12 2:19:15 > top of Java-index,Java Essentials,Java Programming...
# 2

> i want the code for saving a vector to file, and then loading the file back into a vector

Then you'll have to write something like:

void saveVector(Vector<SomeObject> vect, File someFile) {

get output stream writer for someFile;

for each object in vect {

write object to stream;

}

close stream writer;

}

Vector loadVector(File someFile) {

get BufferedReader for someFle;

while read next line {

parse line into object

put object in vector

}

close reader

}

You could also save your objects to XML (especially if your object has a lot of references to other classes)

Peetzorea at 2007-7-12 2:19:15 > top of Java-index,Java Essentials,Java Programming...