• Post Reply Bookmark Topic Watch Topic
  • New Topic

StreamCorruptedException  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting StreamCorruptedException when I try to run this code:

*******

import java.io.*;
class rect implements Serializable
{
private int l;
private int w ;
rect()
{
}
rect(int a , int b)
{
l = a ; w = b;
}
}
class rect_ser
{
public static void main(String a []) throws Exception
{
rect r1 = new rect(1,2);
rect r2 = new rect(3,4);
FileInputStream inp_st = new FileInputStream("c:\\r.txt"); FileOutputStream out_st = new FileOutputStream("c:\\r.txt"); ObjectInputStream oi = new ObjectInputStream(inp_st);
ObjectOuputStream oo = new ObjectOutputStream(out_st);
oo.writeObject(r1);
oo.writeObject(r2);
}
}

Later on , I found out that order should be:
1.FileOutputStream
2.FileInputStream
3.ObjectOutputStream
4.ObjectInputStream.
If you code 2,1,4,3 , StreamCorruptedException is generated...
Is it true..

 
Lucy C
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
psethura, if you only want to write the objects, why have you created an input stream? Just wondering....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!