The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Type code out of range, is -84

Posted by Senthoor on December 08, 2001 at 10:25 PM

import java.io.*;

class test implements java.io.Serializable
{
public String x = null;
public int i = 0;

public test(String y, int x)
{
this.x = y;
this.i = x;
}
}

public class FileIO {

public FileIO() {
}
public static void main(String[] args) {

try
{
// writing to the file
FileOutputStream fo = new FileOutputStream("x.dat");
ObjectOutputStream oo = new ObjectOutputStream(fo);

test x = new test("Senthoor",5);
oo.writeObject(x);
oo.flush();
oo.close();
fo.close();


// writing again to the file
fo = new FileOutputStream("x.dat", true);
oo = new ObjectOutputStream(fo);

test y = new test("Luxman",10);
oo.writeObject(y);
oo.flush();
oo.close();
fo.close();


//reading from the file

FileInputStream fi = new FileInputStream("x.dat");
ObjectInputStream oi = new ObjectInputStream(fi);
oi.readObject();
test z = (test)oi.readObject();
System.out.println("String : " + z.x);
System.out.print("int : " + z.i);
fi.close();
}
catch(Exception e)
{
System.out.println("ERROR : " + e.toString());
}
}
}

Whats wrong with this code.... the same problem is coming again?



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us