I have saved an object to an array list and saved the file as .dat, but when I want to read the object it is just showing null and not the values.
The Class
public class Person implements Serializable {
public static String Name;
public static String Contact;
public Person(String Name, String Contact) {
this.Name = Name;
this.Contact = Contact;
}
public String getName() {
return Name;
}
public String getContact() {
return Contact;
}
}
The code
FileInputStream fis;
try {
fis = new FileInputStream("Person.dat");
ObjectInputStream ois = new ObjectInputStream(fis);
ArrayList<Person> per = (ArrayList<Person>) ois.readObject();
ois.close();
per.get(0);
Person pe = per.get(0);
System.out.println(pe.getName());
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}