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
> 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)