Results 1 to 2 of 2
  1. #1
    AkisV is offline Member
    Join Date
    Sep 2008
    Posts
    2
    Rep Power
    0

    Default Saving and updating a single file

    Hey everyone.

    I'm trying to make it possible to save program data into a single file in a way.

    The problem is that I want to save multiple entries and load any one them at any time through my program but each time I save a new entry, instead of adding it as a second entry, it overwrites the existing one.

    Here's my code:


    private void SaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveActionPerformed
    Vector<PointOnFret> vectorToSave = gPanel1.getFretPointsVector();
    String chordName = JOptionPane.showInputDialog("Enter chord name");
    Chord chordToSave = new Chord();
    chordToSave.setName(chordName);
    chordToSave.setPositions(vectorToSave);

    try{
    FileOutputStream fis = new FileOutputStream(FILENAME) ;
    ObjectOutputStream out = new ObjectOutputStream(fis) ;
    out.write(chordToSave);
    out.flush();
    out.close();
    }


    Can you see any problem?

    Pls help

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Read the API doc for the classes you are using to write a file. Some of them take an arg that says to APPEND the data to the file vs replacing the data in the file.

Similar Threads

  1. [SOLVED] jfilechooser for saving a file....?
    By prabhurangan in forum AWT / Swing
    Replies: 10
    Last Post: 10-06-2013, 11:17 PM
  2. Saving Values
    By Sysem in forum New To Java
    Replies: 10
    Last Post: 06-02-2008, 07:29 PM
  3. Saving data in an XML file
    By Thez in forum New To Java
    Replies: 1
    Last Post: 12-08-2007, 10:24 PM
  4. Replies: 1
    Last Post: 06-06-2007, 05:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •