Sunday, 15 September 2013

Saving objects with Java

Saving objects with Java

I have a question about the following code. I create three instances of my
Player class, and then I save them to a file.
Player a = new Player(1, "asd");
Player b = new Player(2, "asd");
Player c = new Player(3, "asd");
try {
FileOutputStream fos = new FileOutputStream("Game.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(a);
oos.writeObject(b);
oos.writeObject(c);
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
What happens with Game.ser? Is this a file that's actually created, or is
it just within the program? If not, where is it located? I don't find it
in any project folder.
The program works fine. Im just wondering about where the objects are saved.

No comments:

Post a Comment