Do you mean that you want to overwrite the file?
–
Bill the LizardDec 8 '09 at 1:30

Could you please explain better? Not sure what you mean by, "data stays in." What is the data staying in? Posting some code might help.
–
Matthew SowdersDec 8 '09 at 1:34

Like, I write some data, save it and without exiting the program, go to a command named New which should open a new empty file. A bit like word and other text editors. However, when I use the new command, same data as saved is still there.
–
MartinDec 8 '09 at 1:41

1

You'll probably need to show some of your code before people are able to help you...
–
hartoDec 8 '09 at 1:46

That's alot of code. Assume a class that has an employee tree of data. You serialize it with a save command that does WriteObject then, inside the same program you use the new button and you get an empty tree of employees, not the one you just serialized. Was it clear this time?
–
MartinDec 8 '09 at 2:58

2 Answers
2

If you specify an attribute with the keyword transient, then it will not be serialized. If you're saving the data by serializing objects and writing them to files, this may be what you're looking for. Here's an example of using the transient keyword.

Shouldn't creating a new instance of whichever class you are serializing give you such an 'empty data record'?

Using the example of a text editor you use, you would have, say, a Document class which completely encapsulates a text document and assume you use serialization to save it, then simply new Document() would give you an empty document... Until you fill in some text (or data in your program) you shouldnt open a file...

Assuming you meant a tree of Employee data, or a tree data structure with Employee objects at its nodes, then creating a new such tree will give you what you want.

Think, how did you create the first data set that you serialized? Just repeat that process...