Hi,
I am using objectoutputstream to read/write the contents of an array
to the file.
I dont get any problem if i read the file but i am encountering
the following error when i try to read from the file.
Reading from ObjectOuputStream
java.lang.ClassCastException: [LPatient;
at Ward.main(Ward.java:368)
Any help is appreciated.
Following are the two class files that i have been using.
public class Patient implements Serializable
{
private
String name = null;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
public class Ward
{
public static void main(String args[]) throws Exception
{
try
{
Patient[] patients = new Patient[1];
patients[0] = new Patient();
//Writing to File
patients[0].setName("Ravi");
File file = new File("myfile");
FileOutputStream fOS = new FileOutputStream (file);
ObjectOutputStream oOS = new ObjectOutputStream (fOS);
oOS.writeObject (patients);
//Reading From File
File myFile = new File("myfile");
FileInputStream fIS = new FileInputStream (myFile);
ObjectInputStream oIS = new ObjectInputStream(fIS);
patients[0] = (Patient) oIS.readObject();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}