I'm having a problem creating a method to save a list of buttons in a file and then load them back into my program when it开发者_Go百科 starts again. Simply put, how do I save a list into a file and then load that file back up as a list again?
One possibility is to use:
FileOutputStream file = new FileOutputStream("filename");
ObjectOutputStream out = new ObjectOutputStream(file);
Then you can use
out.writeObject(ArrayOfObjects[i]);
to save an element to the file. You will have to iterate over all elements of the list.
EDIT: I dont't know whether it is possible to use something like
out.writeObject(TheWholeList)
But you should definitely try it .
精彩评论