java loading data from file

Soldato
Joined
2 Oct 2004
Posts
4,362
Location
N.W London
Hi Guys

I am trying to restore the state of a program using JAVA which I saved in a file.

When the user clicks on "restore" the program should overwrite the existing object with the data from the object stored in the file.

Here is what I have:


public Record restore(String file)
{
try
{
FileInputStream ins = new FileInputStream(file);
ObjectInputStream outs = new ObjectInputStream (ins);

Artist loadArtists = (Artist)outs.readObject();
outs.close();
return loadArtists;
}
catch (FileNotFoundException e) {System.out.println (e);}
catch (IOException e) {System.out.println (e);}
catch (ClassNotFoundException e) {System.out.println (e);}

return null;
}

This code reads in the object saved to file and returns it but does not overwrite the existing object.

I dont know why?

Can you help me overwrite the existing object with the object I retrieve from the file?

Thanks in advance for any help I receive

Cheers
 
but I have to "cast" the data I read in don't I?

I thought I could read in the entire object and simply overwrite the existing one?

Please advise

thanks for your help
 
thank you so much for this is worked a treat....

basically all I had to do was define the fields I was currently using and then pass the data into them from the objects stored in my file.

really appreciate all your help

cheers guys :-)
 
Back
Top Bottom