This is my first post and its a doozie...
I am trying to write a object to file (which I think works) and then read the object in from that file.
The problem is that the variables dont seem to be reading in as well...
These are the functions I am using...
@Override
void writeToFile(String filename)//Writes the object to a file
{
FileOutputStream fos = null;
ObjectOutputStream out = null;
try
{
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(this);
out.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
@Override
void readFromFile(String filename)
{
try
{
InputStream file = new FileInputStream( filename );
ObjectInput input = new ObjectInputStream ( file );
try
{
Circle readShapes = (Circle)input.readObject();
System.out.println("Recovered Shape: " + readShapes.ShapeToString());
}
finally
{
input.close();
}
}
catch(ClassNotFoundException ex)
{
System.out.println("Error: " + ex.getMessage());
}
catch(IOException ex)
{
System.out.println("Error: " + ex.getMessage());
}
}
Thank you in advance for the help... :pinguin:
Edited by ZekeDragon, 15 March 2010 - 05:33 AM.
Please use [code] tags around program code.


Sign In
Create Account


Back to top









