What you've done is serialize a Java object to a file with ObjectOutputStream
. That means, Java transforms your object Clients
into a specific representation, which covers all the state your object has, e.g. member variables. This representation is not meant to be human-readable, it is a binary format, which is more efficient and suitable for classes and the Java enviroment, than a text format. Look here for more information.
What you can do instead is use a FileWriter
, BufferedWriter
or PrintWriter
, which have multiple write[...](...)
methods to write text to a file. In this case, you have to write each variable for its own as String
, etc., not the whole class. Here you can an find example on that.
Another option to do the same as ObjectOutputStream
for a whole object but in a completely customizable fashion and human-readable form is to use the Java Architecture for XML Binding (JAXB), but this requires a bit of reading. There are also other object serialization libraries for JSON and other formats.