Posted By:
Anonymous
Posted On:
Saturday, September 8, 2001 06:22 AM
Hi Guy's !!! Wanted to pass formatted text in a Chat Appl. Have created the following files : import java.text.*; import java.io.*; public class FlashAttributedString extends AttributedString implements Serializable { public FlashAttributedString(String text) { super(text); } } This class extends the class AttributedString and implements the Serializable interface.This class is then used in the following code : import java.io.*; public class SerializationDemo { public static void main(String args[]) { t
More>>
Hi Guy's !!!
Wanted to pass formatted text in a Chat Appl.
Have created the following files :
import java.text.*;
import java.io.*;
public class FlashAttributedString extends AttributedString implements Serializable
{
public FlashAttributedString(String text)
{
super(text);
}
}
This class extends the class AttributedString and implements the Serializable interface.This class is then used in the following code :
import java.io.*;
public class SerializationDemo
{
public static void main(String args[])
{
try
{
FlashAttributedString obj = new FlashAttributedString("This is Seriaized");
System.out.println("obj = " + obj);
FileOutputStream fos = new FileOutputStream("serial.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
oos.flush();
oos.close();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
FlashAttributedString obj1;
FileInputStream fis = new FileInputStream("serial.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
obj1=(FlashAttributedString)ois.readObject();
ois.close();
System.out.println("obj1 = " + obj1);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
On executing this file an exception was thrown at the line
ois.readObject();
.
The Exception thrown was:
java.io.InvalidClassException:java.text.AttributedString;
How should it be rectified ? Pls Suggest.
Thanks Guy's .
<<Less