Consider a sample code:
1 public class Test implements Serializable {
2 private static final long serialVersionUID = 1L;
3 public static void main(String[] args) {
4 Test ts = new Test();
5 int value = 11;
6 try {
7 FileOutputStream fos = new FileOutputStream("savedata.ser");
8 ObjectOutputStream os = new ObjectOutputStream(fos);
9 os.writeObject(ts);
10 os.close();
11 // Place code here
12 ObjectInputStream is = new ObjectInputStream(fs);
13 Test ts2 = (Test) is.readObject();
14 System.out.print(ts2.value);
15 is.close();
16 } catch (Exception x) {
}}}
What will be placed at line no-15 for desirialization ?
(A) FileInputStream fs = new FileInputStream(new DataOutputStream("savedata.ser"));
(B) FileInputStream fs = new FileInputStream("savedata.ser");
(C) DataOutputStream("new FileInputStream("savedata.ser") ");
(D) DataOutputStream("savedata.ser");
(B)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.