Can i write oblects in java into file and retrieve the same?? In c++ we ise wrie function.. can i realize this in java?
In C++ we may use
fin.write((char*)&object,sizeof(classname));
how can i realize this in java.?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use an ObjectOutputStream to serialize objects to a file (or any other output stream) and ObjectInputStream to read them back in. Objects need to implement the Serializable interface to be useful with these classes. Not all objects can be serialized. (For example, it wouldn’t make sense or be very useful to serialize a socket.)