Random Access Saving

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

    Random Access Saving

    I'm trying to save fixed length data into a random access file. Right now it works, but saves everything in one, continuous line. How can save every new entry in a new line. Also, I want to separate fields with a "|" character in order to read the file into a JTable.

    i.e:

    Id|Name|City|Ph one
    102|Beth Reiser|New York|(212)55587 25
    111|Dylan Ricci|Syracuse| (315)5554486
    116|Brian Gugliuzza|Mamar oneck|(914)5553 817
    120|Gertrude Stein|Elmsford| (914)5553476
    131|Daljit Sinnot|Bohemia| (516)5559811


    public void writeDetails() {

    try {

    patient a = new patient();

    a.patName = name.getText();
    a.patSurname = surname.getText ();
    a.patDob = dobInput.getTex t();
    a.patAddress = addInput.getTex t();
    a.patEmgNum = emgInput.getTex t();
    a.patCheckInDat e = dateInput.getTe xt();
    a.patCheckInTim e = timeInput.getTe xt();
    a.patWard = (String)wardCom bo.getSelectedI tem();
    a.patDoctor = (String)doctorC ombo.getSelecte dItem();

    raf.seek(raf.le ngth());
    FixedLengthStri ngIO.writeFixed LengthString(a. patNa me, NAME_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patSu rname, SURNAME_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patDo b, DOB_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patAd dress, ADD_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patEm gNum, EMG_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patCh eckInDate, DATE_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patCh eckInTime, TIME_SIZE, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patWa rd, 20, raf);
    FixedLengthStri ngIO.writeFixed LengthString(a. patDo ctor, 30, raf);

    JOptionPane.sho wMessageDialog( null, "PATIENT DETAILS SAVED", "INFORMATIO N", JOptionPane.INF ORMATION_MESSAG E);

    } catch (IOException ex) {

    ex.printStackTr ace();

    }
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Where did you get the FixedLengthStri ngIO class from (It's not part of the standard Java packages)? You need to read its documentation to find out how to make it put newlines.

    Comment

    Working...