hello everyone i have two question while doing a java program and need some help from you guys.I have 2 questions
1) public WriteFile { public static void main(String args[]) {
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("StudentDB"));
//a class i created to create studnent Student studentA = new Student(); output.writeObject(studentA); output.flush(); output.close();
} }
//another class
public WriteFile2 { public static void main(String args[]) {
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("StudentDB"));
Student studentB = new Student(); output.writeObject(studentB); output.flush(); output.close(); }}
Qu estion 1: i expect the result after running this two program is the file "studentDB" to carries the two object but instead, the 2nd program overrides the "studentDB".Can anyone teach me how can i write 2 objects in 2 seperate main method without overriding the file.
Question 2: after writing the "studentDB" file, i can read the Objects from it. But the problem is i wanted to get the Object, pass some methods to the object(eg . studentA.setName() ) and save it back "studentDB" do anyone here knows how to do it. I been trying this the whole day and can't get a solution
Thank you for your solution!! thats the only way i can do i guess . I will try to work out with this and if i encounter any problem , hope and i can get back to you in this forum for some guidance.Sorry, my english is bad =p thankyou