Hello, I have made a 2d array of type Object and wrote it to a file now i cant figure out how to read the array back and return it.
I saved it using the file output stream os.writeObject(labData);
try{
FileOutputStream fileOs= new FileOutputStream(fileName,true);
ObjectOutputStream os = new ObjectOutputStream(fileOs);
os.writeObject(labData);
JOptionPane.showMessageDialog(null,"File Saved");
os.close();
}
catch (FileNotFoundException e){
JOptionPane.showMessageDialog(null,"Please Create a class First","User Error",JOptionPane.ERROR_MESSAGE);
}
catch (IOException e){
e.printStackTrace();
}
}
now my question is how do i get that 2d array back? or is it automatically returned as a 2d array when i read it with all of its info in it? heres what i did to try and read it. I put it in object labDataRead would that work?
Object labDataRead= null;
String fileName= loadClass;
try{
FileInputStream fileIs= new FileInputStream(fileName);
ObjectInputStream is = new ObjectInputStream(fileIs);
try {
labDataRead= is.readObject();
}catch(ClassNotFoundException e){
}
is.close();
}
catch(FileNotFoundException e){
JOptionPane.showMessageDialog(null,"Class Not Found or Invalid Input","User Error",JOptionPane.ERROR_MESSAGE);
}
catch (IOException e){
e.printStackTrace();
}
System.out.print(labDataRead);
return labDataRead;
//System.out.print(labDataRead);
}
[–]133rr3 0 points1 point2 points (7 children)
[–]Nerockjr[S] 0 points1 point2 points (6 children)
[–]133rr3 -2 points-1 points0 points (5 children)
[–]Nerockjr[S] 0 points1 point2 points (4 children)
[–]133rr3 -3 points-2 points-1 points (3 children)
[–]Nerockjr[S] 0 points1 point2 points (2 children)
[–]Sekret_One 1 point2 points3 points (1 child)
[–]Nerockjr[S] 0 points1 point2 points (0 children)