I
Ian Pilcher
I have a class which has a single field:
private final File nameFile;
When serializing it, I want to save it as a String, rather than a File.
This will allow me to better check for platform incompatibilities during
deserialization.
I can serialize it like so:
private transient final File nameFile;
private void writeObject(ObjectOutputStream out) throws IOException
{
out.defaultWriteObject();
out.writeObject(nameFile.getPath());
}
A straightforward approach to deserialization won't work, however, for
the obvious reason that I won't be able to set nameFile to the File I
construct from my deserialized String.
I can't be the first person to run into this. What have others done in
this situation?
Thanks!
private final File nameFile;
When serializing it, I want to save it as a String, rather than a File.
This will allow me to better check for platform incompatibilities during
deserialization.
I can serialize it like so:
private transient final File nameFile;
private void writeObject(ObjectOutputStream out) throws IOException
{
out.defaultWriteObject();
out.writeObject(nameFile.getPath());
}
A straightforward approach to deserialization won't work, however, for
the obvious reason that I won't be able to set nameFile to the File I
construct from my deserialized String.
I can't be the first person to run into this. What have others done in
this situation?
Thanks!