can write code for serialization ?
Answer / bharat shivram
import java.io.*;
public class SerializationDemo {
public static void main(String args[]) {
// Object serialization
try {
MyClass object1 = new MyClass("Hello", -7, 2.7e10);
System.out.println("object1: " + object1);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Exception during serialization: " + e);
System.exit(0);
}
| Is This Answer Correct ? | 3 Yes | 0 No |
How do you access command-line arguments within the code?
1 Answers Flextronics, Hexaware,
how to run ecllipse with jettyserver for windows environment using batch file
What method is used to compare two strings ?
What is native code?
What is a map? What are the implementations of map?
In how many ways we can do exception handling in java?
What do you mean by light weight and heavy weight components?
How do you convert string to int in java?
Can a static method be overridden in java?
Why we need to serialize the object
11 Answers CTS, Geometric Software,
What is a local block?
difference between String a; and String a=new String();? y do v need to assign memory to the variable?