Re: How to write Array of Object to a file?
- From: Lew <lew@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 07 May 2007 08:34:58 -0400
Please do not top-post, not even to your own posts.
DL wrote:
Here is a class the does the writing, but i am getting exceptions saying its not serialized.etc.
I doubt very much that any error message included the word "etc." Are you certain that you copied and pasted the error messages correctly?
import java.io.*;
public class WriteStudentData {
/** Creates a new instance of WriteStudentData */
public WriteStudentData() {
}
// method will take the student list and save it to student.dat file.
public void save(Student[] student)
{
try {
ObjectOutputStream objOut = new ObjectOutputStream(new FileOutputStream("student.dat"));
objOut.writeObject(student);
objOut.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Read the Javadocs on java.io.Serializable. It will explain why you cannot use ObjectOutputStream yet for the Student type.
Incidentally you get better results on newsgroups if you post an SSCCE. Without the source for the Student class in hand we have to guess (correctly) why you cannot serialize the class.
BTW, there are other ways to write information to a file than serialization.
--
Lew
.
- Follow-Ups:
- Re: How to write Array of Object to a file?
- From: DL
- Re: How to write Array of Object to a file?
- From: Robert Larsen
- Re: How to write Array of Object to a file?
- References:
- Prev by Date: Re: How to write Array of Object to a file?
- Next by Date: Re: How to write Array of Object to a file?
- Previous by thread: Re: How to write Array of Object to a file?
- Next by thread: Re: How to write Array of Object to a file?
- Index(es):
Relevant Pages
|
|