This is my code snippet.I want to return 2D Object type array from the file data.txt
But i am getting error in the line labeled (1).
How can i achieve this.
Object data[][]=new Object[200][3];
try {
ObjectInputStream ois=new ObjectInputStream(new FileInputStream("data.txt"));
data=ois.readObject(); // error line!!!(1)
} catch(Exception exc) {
System.out.println("error reading data.txt");
}
readObject()returns anObject. If you know that the object is infact aObject[][], then you can cast it:Also: you don’t need create the 2D array in the first line, as that object will be discarded when you replace it with the one read from the file.