开发者

java save list<JButton>

开发者 https://www.devze.com 2023-03-31 02:54 出处:网络
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

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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消