Question

I have this simple application with a couple of classes which are all related. There's one, the main one, for which there is only one instance of. I need to save save and load that using a text stream.

My instructor requirement is BufferedReader to load the stream and PrintWriter to save it. But is this even possible? To persist a data object/class with a text stream?

I know how to do it with an object, using serialization. But I don't see how am I supposed to do it using text streams.

Suggestions?

Was it helpful?

Solution

You need to define your own, simple, serialization protocol. Writing writes out the fields that need to be saved, reading reads them back in.

OTHER TIPS

You actually have to figure it on your own to be helpfull for you :). What i can say that you can reformulate it like this:

Save and load the state of a class and of related members assuming you only have the BufferedReader and PrintWriter IO classes available (along with FileReader, FileWriter classes) and no serialization framework in place in the language.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top