Note that there are some explanatory texts on larger screens.

plurals
  1. POException StreamCorruptedException: invalid type code: AC
    primarykey
    data
    text
    <p>I want to serialize a same object on file, each time when i run a program. This is a simple algorithm to explain my problem.</p> <p>In the begening i store a <code>String</code> on <code>writer</code>. in the last i read a file. The goal of this program is if i run my program X time, i store and i print on screen X time my object.</p> <pre><code>class ReadFile { static ObjectOutputStream writer = null; public static void main(String[] args) throws IOException, ClassNotFoundException { writer = new ObjectOutputStream(new FileOutputStream("trace", true)); store("String"); if (writer != null) { writer.close(); } open("file.tmp"); } static public void store(String chaine) { if (writer == null) { return; } try { writer.writeObject(chaine); } catch (IOException ex) { } } static public void open(String file) throws FileNotFoundException, IOException, ClassNotFoundException { StringBuilder str = new StringBuilder(); ObjectInputStream objs; try { objs = new ObjectInputStream(new FileInputStream(file)); try { while (true) { Object obj = objs.readObject(); str.append(obj.toString()); } } catch (EOFException ex) { } objs.close(); } catch (Exception ex) { ex.printStackTrace(System.err); } } } </code></pre> <p>When i run this program i have this error :</p> <pre><code>java.io.StreamCorruptedException: invalid type code: AC at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1355) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at ReadFile.open(ReadFile.java:47) at ReadFile.main(ReadFile.java:35) </code></pre> <p>What can i do please ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload