Note that there are some explanatory texts on larger screens.

plurals
  1. POA problem with java Object Streams while writing to file
    primarykey
    data
    text
    <p>I am trying to write an Object of kind "HashMap" to a file &amp; recover it when my program run again. But I faced with an EOFException when I try to read that object and the Object is not read from the file. I use the flush() &amp; close() methods when I wrote the object for the FileOutputStream &amp; ObjectOutputStream. Also I create OutputStream &amp; InputStream together for my file. here is my code:</p> <pre><code>DataOutputStream outToFile; DataInputStream inFromFile; ObjectOutputStream writeTableToFile; ObjectInputStream readTableFromFile; File tableFile; public DNS(){ try { tableFile = new File("table.txt"); outToFile = new DataOutputStream(new FileOutputStream(tableFile) ); writeTableToFile = new ObjectOutputStream(outToFile); inFromFile = new DataInputStream(new FileInputStream(tableFile)); readTableFromFile = new ObjectInputStream(inFromFile); HashMap table2 = (HashMap) readTableFromFile.readObject(); if (table2 == null) table=new HashMap(100); else table = table2; } catch (FileNotFoundException e) { e.printStackTrace(); }catch(EOFException e){ table=new HashMap(100); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } </code></pre> <p>}</p> <p>and here is code for writing object:</p> <pre><code> table.put(NameField.getText(), IPField.getText()); try { //writeTableToFile.reset(); writeTableToFile.writeObject(table); writeTableToFile.flush(); } catch (IOException e1) { e1.printStackTrace(); } </code></pre> <p>Regards, sajad</p>
    singulars
    1. This table or related slice is empty.
    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.
    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