ObjectOutputStream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MiziaQ
    New Member
    • Nov 2007
    • 63

    ObjectOutputStream

    I have this code to write to a file. However, this only saves one entry.
    How can I save multiple entries, each saved in separate lines ?
    At this point the output in the .txt file is strange:

    ’ t Peter|t Pan|t 01/09/67|t 098 1456789|t 18-Mar-2009|t Male Surgical Wardt 

    I need the text to be clear in order to read it in a JTable


    public void writeTable() {

    try {

    String ward = (String)wardCom bo.getSelectedI tem();

    ObjectOutputStr eam file = new ObjectOutputStr eam
    (new FileOutputStrea m("tablePat.txt "));

    file.writeObjec t(name.getText( ) + "|");
    file.writeObjec t(surname.getTe xt() + "|");
    file.writeObjec t(dobInput.getT ext() + "|");
    file.writeObjec t(emgInput.getT ext() + "|");
    file.writeObjec t(dateInput.get Text() + "|");
    file.writeObjec t(ward);
    file.writeObjec t("\n");
    file.close();

    } catch (IOException ex) {

    ex.printStackTr ace();

    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    An ObjectOutputStr eam doesn't write text; it writes a serialized version of objects instead. That serialized version can be read in again and a new object can be constructed out of that (non-text) data again by an ObjectInputStre am. If you want text you're using the wrong stream for the purpose.

    kind regards,

    Jos

    Comment

    Working...