I'm making a program that opens a previous saved file through serialization and开发者_运维百科 want to create a new one, however, data stays in.
How can I make the program forget the data?
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...
精彩评论