File IO not reading or writting

Hi. I'm having fun learning how to write and read a file. My code seems to not want to either write or is not properly reading the file record. I don't quite understand File IO just yet and I could use some pointers. (FYI - I have two external classes that create the GUI objects and have the set and get methods)
import java.text.DecimalFormat;               
import java.io.*;
import java.io.Serializable;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.A5.Gonzalez.A5UI;
import com.A5.Gonzalez.Employee;
public class A5Main extends JFrame
     private ObjectOutputStream output;
     private ObjectInputStream input;
     private File file;
     private A5UI userInterface;
     private JTextArea txtADisplay;
     private JPanel pnlDisplay;
     private JButton btnSave, btnOpen, btnIncSal, btnEnter;
    private int id[];
    private String name[];
    private double salary[];
     Employee record;
     int counter = 0;
     DecimalFormat twoDigits = new DecimalFormat( "0.00" );
     public A5Main()               
          super( "Increase Salary by 10%" );
          id = new int[ 3 ];
          name = new String[ 3 ];
          salary = new double[ 3 ];
          userInterface = new A5UI();
          getContentPane().add( userInterface );
          userInterface.setFieldEditable( false );
          btnSave = userInterface.getDoTask1Btn();
          btnSave.setText( "Save File" );
          btnSave.addActionListener(
               new ActionListener()
                    public void actionPerformed( ActionEvent e )
                         saveFile();
          btnOpen = userInterface.getDoTask2Btn();
          btnOpen.setText( "Display Record" );
          btnOpen.setEnabled( false );
          btnOpen.addActionListener(
               new ActionListener()
                    public void actionPerformed( ActionEvent e )
                         showOutput();
          btnIncSal = userInterface.getDoTask3Btn();
          btnIncSal.setText( "Increase Salary by 10%" );
          btnIncSal.setEnabled( false );
          btnIncSal.addActionListener(
               new ActionListener()
                    public void actionPerformed( ActionEvent e )
//                         closeInput();
//                         openFile();
//                         incSalary();
          btnEnter = userInterface.getDoTask4Btn();
          btnEnter.setText( "Enter Record" );
          btnEnter.setEnabled( false );
          btnEnter.addActionListener(
               new ActionListener()
                    public void actionPerformed( ActionEvent e )
                         enterRecord();
          setSize( 350, 200 );
          show();
     public void saveFile()
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
          fileChooser.setCurrentDirectory( new File(".") );
          int result = fileChooser.showSaveDialog( this );
          if( result == JFileChooser.CANCEL_OPTION )
               return;
          file = fileChooser.getSelectedFile();
          if( file == null || file.getName().equals( "" ) )
               JOptionPane.showMessageDialog( this,
                    "Invalid File Name", "Invalid File Name",
                    JOptionPane.ERROR_MESSAGE );
          else
               try
                    output = new ObjectOutputStream(
                         new FileOutputStream( file ) );
                    record = new Employee( );
                    output.writeObject( record );
                    output.flush();
               catch( IOException ioException)
                    JOptionPane.showMessageDialog( this,
                         "Error Opening File", "Error",
                         JOptionPane.ERROR_MESSAGE );
               userInterface.setFieldEditable( true );
               btnSave.setEnabled( false );
               btnEnter.setEnabled( true );
     private void openFile()
          if( file == null || file.getName().equals( "" ) )
               JOptionPane.showMessageDialog( this,
                    "Invalid File Name", "Invalid File Name",
                    JOptionPane.ERROR_MESSAGE );
          else
               try
                    input = new ObjectInputStream(
                         new FileInputStream( file ) );
               catch( IOException ioException)
                    JOptionPane.showMessageDialog( this,
                         "Error Opening File", "Error",
                         JOptionPane.ERROR_MESSAGE );
     public void enterRecord()
          Employee record;
          int idNum = 0;
          String fieldValues[] = userInterface.getFieldValues();
          if( ! fieldValues[ A5UI.ID ].equals( "" ) )
               try
                    idNum = Integer.parseInt( fieldValues[ A5UI.ID ] );
                    id[ counter ] = idNum;
                    name[ counter ] = fieldValues[ A5UI.NAME ];
                    salary[ counter ] = Double.parseDouble( fieldValues[ A5UI.SALARY ] );
                    ++counter;
                    userInterface.clearFields();
                    if( counter > 2 )
                         userInterface.setFieldEditable( false );
                         btnEnter.setEnabled( false );
                         btnOpen.setEnabled( true );
                         writeRecord();
               catch( NumberFormatException formatException )
                    JOptionPane.showMessageDialog( this,
                         "Bad id number or salary value",
                         "Invalid Number Format",
                         JOptionPane.ERROR_MESSAGE );
               catch( ArrayIndexOutOfBoundsException arrayOutBoundsEx )
                    JOptionPane.showMessageDialog( this,
                         "You can only enter a maximum of 3 records",
                         "Array Index Out Of Bounds Exception",
                         JOptionPane.ERROR_MESSAGE );
                    userInterface.clearFields();
     private void writeRecord()
          try
               JOptionPane.showMessageDialog( this, "What the &^%* is going on?",
                                             "test", JOptionPane.ERROR_MESSAGE );
               for ( int counter = 0; counter< id.length; counter++ )
                    if( id[ counter ] == 0)
                         break;
                    record = new Employee( id[ counter ],
                                              name[ counter ],
                                              salary[ counter ] );
                    output.writeObject( record );
               output.flush();
               closeOutput();
          catch( IOException ioException )
               closeOutput();
     private void closeOutput()
          try
               output.close();
          catch( IOException ioException )
               JOptionPane.showMessageDialog( this,
                    "Error closing file", "Error",
                    JOptionPane.ERROR_MESSAGE );
               System.exit( 1 );
     private void closeInput()
          try
               input.close();
          catch( IOException itException )
               JOptionPane.showMessageDialog( this,
                    "Error closing file", "Error",
                    JOptionPane.ERROR_MESSAGE );
               System.exit( 1 );
     public void readRecord()
          counter = 0;
          Employee record;
          try
               if( counter < id.length )
                    record = ( Employee ) input.readObject();
                    id[ counter ] = record.getID();
                    name[ counter ] = record.getName();
                    salary[ counter ] = record.getSalary();
                    counter++;
          catch( EOFException endOfFileException )
               JOptionPane.showMessageDialog( this, "There are no more records",
                    "End of File", JOptionPane.ERROR_MESSAGE );
          catch( ClassNotFoundException classNotFoundException )
               JOptionPane.showMessageDialog( this,
                    "Unable to Create Object", "Class Not Found", JOptionPane.ERROR_MESSAGE );
          catch( IOException ioException )
               JOptionPane.showMessageDialog( this,
                    "Error reading the file", "File Read Error", JOptionPane.ERROR_MESSAGE );
     public void showOutput()
          openFile();
          readRecord();
          counter = 0;
          txtADisplay = new JTextArea( 8, 8 );
          txtADisplay.setEditable( false );
          pnlDisplay = new JPanel();
          String theTextOut = "Employee Information";
          theTextOut += "\n\nID\tName\t\tSalary";
          if( counter < id.length )
               theTextOut += "\n" + id[ counter ];
               theTextOut += "\t" + name[ counter ];
               theTextOut += "\t\t" + salary[ counter ];
               counter++;
          txtADisplay.setText( theTextOut );
          pnlDisplay.add( txtADisplay );
          JOptionPane.showMessageDialog( this, pnlDisplay,
                    "Testing", JOptionPane.PLAIN_MESSAGE );
     public void incSalary()
          Employee record;
          try
               record = ( Employee ) input.readObject();
               String values[] = {
                    String.valueOf( record.id ),
                    record.name,
                    String.valueOf( Double.parseDouble( String.valueOf( record.salary ) ) * 1.1 ) };
               userInterface.setFieldValues( values );
          catch( EOFException endOfFileException )
               JOptionPane.showMessageDialog( this, "There are no more records",
                    "End of File", JOptionPane.ERROR_MESSAGE );
          catch( ClassNotFoundException classNotFoundException )
               JOptionPane.showMessageDialog( this,
                    "Unable to Create Object", "Class Not Found", JOptionPane.ERROR_MESSAGE );
          catch( IOException ioException )
               JOptionPane.showMessageDialog( this,
                    "Error reading the file", "File Read Error", JOptionPane.ERROR_MESSAGE );
     public static void main( String args[] )
          new A5Main();
[\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Ok well I KNOW that the btnEnter calls method enterRecord() which grabs the data from the fiends (limited to 3 entries) and then calls writeRecord(); Why write a separate class file to do the same thing that writeRecord() or readRecord() does? The point is that if it is writing then there is no way to know because when the file is read it returns 0 for the values of the record value. Are they getting wiped out when they are read or are they not even being written?

Similar Messages

  • I purchased an audio book from I tunes but when I sync with my I phone it respond with error saying could not read or write the file. It only sync parts 2

    I purchased an audio book from I tunes but when I sync with my I phone it respond with error saying could not read or write the file. It only sync parts 2

    Those videos are probably not in an iPod-friendly format. It’s picky about that. You can try converting them, if possible.
    As for the audiobooks, are you sure they haven’t synced? You’ve enabled it to sync books and checked the “Audiobooks” section of your iPod?

  • Can not read or write to mac hard drive error

    When attempting to transfer music files from an external usb harddrive formatted in windows into Itunes, I can only successfully import a small fraction of the music, and then its stops with a error, that the Mac HD can not read or write files.

    It's possible the file names have some 'funky' characters in them that the Mac doesn't like ?
    What format is the external drive ?

  • IPhone disk not read or write using iTunes.

    iPhone disk not read or write using iTunes. I've tried the permissions on my MacBook Pro. I'm convinced it's my phone. This just started out of the blue. Any guidance ?

    1. There is no such thing as an "iPhone disk."  Please recheck that error message.
    2. iPhones have NEVER been able to file transfer with BlueTooth to a computer.  The BlueTooth profile has never been part of the iOS.
    3.  What iPhone model and iOS version, and what iTunes version are you using?
    4. Is this phone jailbroken?

  • Why does my mac mini not read or write DVD's?

    Why does my mac mini not read or write DVD's? I have tried different5 brands of media, checked firmware  and followed every 'fix it' available. HELP.
    It is a late 2009

    See my FAQ*:
    http://www.macmaps.com/cdrfailure.html

  • When updating get a message that reads  the disk could not read or write -

    i downloaded several songs from cd (only some cd do not update )- all loaded up well in i tunes - but when i update - i get a message on the i tunes screen "attempting to copy to the disk david i pod faults - the disk could not read or write- i reinstalled the updated software and i tones software and same problem - only some cd will not update - but they are diffinately in itunes- i can play them on my computer
    nano Windows XP Pro

    Hi daf,
    Try this Your Windows PC doesn't recognize iPod
    Happy New Year
    Colin R.

  • DVD/CD-RW Combo Drive Will Not Read Or Write To Any Media

    I  have an HP ZT1130, running XP SP3.  It has a Toshiba SD-R2102 DVD/CD-RW Combo Drive that will not read or write to any media.  I don't get any error messages.  The drive is present in MY Computer & Device Manager indicates it is working properly.  When I place any disk in the drive, I get a message to "insert a disk".  I have already uninstalled & reinstalled the device, removed the "high & low filters" in the registry, operating from a "clean boot state", run a registry cleaner.  I am currently using Microsoft Media Player 11.  I have run out of things to check, I hope someone has some answers.
    Thanks In Advance,
    nightster 

    I  have an HP ZT1130, running XP SP3.  It has a Toshiba SD-R2102 DVD/CD-RW Combo Drive that will not read or write to any media.  I don't get any error messages.  The drive is present in MY Computer & Device Manager indicates it is working properly.  When I place any disk in the drive, I get a message to "insert a disk".  I have already uninstalled & reinstalled the device, removed the "high & low filters" in the registry, operating from a "clean boot state", run a registry cleaner.  I am currently using Microsoft Media Player 11.  I have run out of things to check, I hope someone has some answers.
    Thanks In Advance,
    nightster 

  • Mac OS X 10.9.1 will not read or write my WD external hard drive. How can I permanently make it so that it can without losing files on drive?

    I have a Macbook pro 10.9.1 that will not communicate with my WD external hard drive. Whenever I connect the drive, this pops up:
    NTFS-3G could not mount /dev/disk1s1
    at /Volumes/Elements because the following problem occurred:
    dyld: Library not loaded: /usr/local/lib/libfuse.2.dylib
      Referenced from: /usr/local/bin/ntfs-3g
      Reason: image not found
    I have important photos and videos on here of my family and can't lose them. I tried downloading multiple third party applications like Tuxera and NFTS 3G but they're only trials. How can I permanently set up my mac to read and write without risking to lose all my stuff on the external hard drive. Thanks in advance for any support.

    babowa, it seems like it is using Fuse & NTFS, so I don't think it's the classic WD + 10.9 mess, but extra WD tools & drivers can still break things MtTran.
    MrTran, if you must use unsupported disk formats on your Mac you must also consider actually paying the developers that made the trial software.
    It's probably a good idea to follow the developers removal instructions, reboot & then install one tool at a time.
    MacFuse, FuseOSX, NTFS-3G are all likley to confict if you run older versions so you need to be sure you are using the latest version. I can't remeber which one depends on the other, so you will need to read the manuals.
    When the disk is readable copy the data to another disk. You could probably do this from a Linux distro or Windows if OS X won't do it.
    If you insist on only using the trial versions you will need to reinstall Mac OS, copy data off this disk & reformat it.
    Is there any good reason for not using the Mac HFS extended format?

  • Why does this class not read and write at same time???

    I had another thread where i was trying to combine two class files together
    http://forum.java.sun.com/thread.jspa?threadID=5146796
    I managed to do it myself but when i run the file it does not work right. If i write a file then try and open the file it says there are no records in the file, but if i close the gui down and open the file everything get read in as normal can anybody tell me why?
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import bank.BankUI;
    import bank.*;
    public class testing extends JFrame {
       private ObjectOutputStream output;
       private BankUI userInterface;
       private JButton SaveToFile, SaveAs, Exit; //////////savetofile also saves to store need to split up and have 2 buttons
       //private Store store; MIGHT BE SOMETHING TO DO WITH THIS AS I HAD TO COMMENT THIS STORE OUT TO GET IT WORKING AS STORE IS USED BELOW
       private Employee record;
    //////////////////////////////////////from read
    private ObjectInputStream input;
       private JButton nextButton, openButton, nextRecordButton ;
       private Store store = new Store(100);
         private Employee employeeList[] = new Employee[100];
         private int count = 0, next = 0;
    /////////////////////////////////////////////from read end
       // set up GUI
       public testing()
          super( "Employee Data" ); // appears in top of gui
          // create instance of reusable user interface
          userInterface = new BankUI( 9 );  // nine textfields
          getContentPane().add( userInterface, BorderLayout.CENTER );
          // configure button doTask1 for use in this program
          SaveAs = userInterface.getSaveAsButton();
          SaveAs.setText( "Save as.." );
    //////////////////from read
    openButton = userInterface.getOpenFileButton();
          openButton.setText( "Open File" );
    openButton.addActionListener(
             // anonymous inner class to handle openButton event
             new ActionListener() {
                // close file and terminate application
                public void actionPerformed( ActionEvent event )
                   openFile();
             } // end anonymous inner class
          ); // end call to addActionListener
          // register window listener for window closing event
          addWindowListener(
             // anonymous inner class to handle windowClosing event
             new WindowAdapter() {
                // close file and terminate application
                public void windowClosing( WindowEvent event )
                   if ( input != null )
                             closeFile();
                   System.exit( 0 );
             } // end anonymous inner class
          ); // end call to addWindowListener
          // get reference to generic task button doTask2 from BankUI
          nextButton = userInterface.getDoTask2Button();
          nextButton.setText( "Next Record" );
          nextButton.setEnabled( false );
          // register listener to call readRecord when button pressed
          nextButton.addActionListener(
             // anonymous inner class to handle nextRecord event
             new ActionListener() {
                // call readRecord when user clicks nextRecord
                public void actionPerformed( ActionEvent event )
                   readRecord();
             } // end anonymous inner class
          ); // end call to addActionListener
    //get reference to generic task button do Task3 from BankUI
          // get reference to generic task button doTask3 from BankUI
          nextRecordButton = userInterface.getDoTask3Button();
          nextRecordButton.setText( "Get Next Record" );
          nextRecordButton.setEnabled( false );
          // register listener to call readRecord when button pressed
          nextRecordButton.addActionListener(
             // anonymous inner class to handle nextRecord event
             new ActionListener() {
                // call readRecord when user clicks nextRecord
                public void actionPerformed( ActionEvent event )
                   getNextRecord();
             } // end anonymous inner class
          ); // end call to addActionListener
    ///////////from read end
          // register listener to call openFile when button pressed
          SaveAs.addActionListener(
             // anonymous inner class to handle openButton event
             new ActionListener() {
                // call openFile when button pressed
                public void actionPerformed( ActionEvent event )
                   SaveLocation();
             } // end anonymous inner class
          ); // end call to addActionListener
          // configure button doTask2 for use in this program
          SaveToFile = userInterface.getSaveStoreToFileButton();
          SaveToFile.setText( "Save to store and to file need to split this task up" );
          SaveToFile.setEnabled( false );  // disable button
          // register listener to call addRecord when button pressed
          SaveToFile.addActionListener(
             // anonymous inner class to handle enterButton event
             new ActionListener() {
                // call addRecord when button pressed
                public void actionPerformed( ActionEvent event )
                   addRecord(); // NEED TO SPLIT UP SO DONT DO BOTH
             } // end anonymous inner class
          ); // end call to addActionListener
    Exit = userInterface.getExitAndSaveButton();
          Exit.setText( "Exit " );
          Exit.setEnabled( false );  // disable button
          // register listener to call addRecord when button pressed
          Exit.addActionListener(
             // anonymous inner class to handle enterButton event
             new ActionListener() {
                // call addRecord when button pressed
                public void actionPerformed( ActionEvent event )
                   addRecord(); // adds record to to file
                   closeFile(); // closes everything
             } // end anonymous inner class
          ); // end call to addActionListener
          // register window listener to handle window closing event
          addWindowListener(
             // anonymous inner class to handle windowClosing event
             new WindowAdapter() {
                // add current record in GUI to file, then close file
                public void windowClosing( WindowEvent event )
                             if ( output != null )
                                addRecord();
                                  closeFile();
             } // end anonymous inner class
          ); // end call to addWindowListener
          setSize( 600, 500 );
          setVisible( true );
         store = new Store(100);
       } // end CreateSequentialFile constructor
       // allow user to specify file name
    ////////////////from read
      // enable user to select file to open
       private void openFile()
          // display file dialog so user can select file to open
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
          int result = fileChooser.showOpenDialog( this );
          // if user clicked Cancel button on dialog, return
          if ( result == JFileChooser.CANCEL_OPTION )
             return;
          // obtain selected file
          File fileName = fileChooser.getSelectedFile();
          // display error if file name invalid
          if ( fileName == null || fileName.getName().equals( "" ) )
             JOptionPane.showMessageDialog( this, "Invalid File Name",
                "Invalid File Name", JOptionPane.ERROR_MESSAGE );
          else {
             // open file
             try {
                input = new ObjectInputStream(
                   new FileInputStream( fileName ) );
                openButton.setEnabled( false );
                nextButton.setEnabled( true );
             // process exceptions opening file
             catch ( IOException ioException ) {
                JOptionPane.showMessageDialog( this, "Error Opening File",
                   "Error", JOptionPane.ERROR_MESSAGE );
          } // end else
       } // end method openFile
    public void readRecord() // need to merger with next record
          Employee record;
          // input the values from the file
          try {
         record = ( Employee ) input.readObject();
                   employeeList[count++]= record;
                   store.add(record);/////////ADDS record to Store
              store.displayAll();
              System.out.println("Count is " + store.getCount());
             // create array of Strings to display in GUI
             String values[] = {
                        String.valueOf(record.getName()),
                            String.valueOf(record.getGender()),
                        String.valueOf( record.getDateOfBirth()),
                        String.valueOf( record.getID()),
                             String.valueOf( record.getStartDate()),
                        String.valueOf( record.getSalary()),
                        String.valueOf( record.getAddress()),
                           String.valueOf( record.getNatInsNo()),
                        String.valueOf( record.getPhone())
    // i added all those bits above split onto one line to look neater
             // display record contents
             userInterface.setFieldValues( values );
          // display message when end-of-file reached
          catch ( EOFException endOfFileException ) {
             nextButton.setEnabled( false );
          nextRecordButton.setEnabled( true );
             JOptionPane.showMessageDialog( this, "No more records in file",
                "End of File", JOptionPane.ERROR_MESSAGE );
          // display error message if class is not found
          catch ( ClassNotFoundException classNotFoundException ) {
             JOptionPane.showMessageDialog( this, "Unable to create object",
                "Class Not Found", JOptionPane.ERROR_MESSAGE );
          // display error message if cannot read due to problem with file
          catch ( IOException ioException ) {
             JOptionPane.showMessageDialog( this,
                "Error during read from file",
                "Read Error", JOptionPane.ERROR_MESSAGE );
       } // end method readRecord
       private void getNextRecord()
               Employee record = employeeList[next++%count];//cycles throught accounts
          //create aray of string to display in GUI
          String values[] = {String.valueOf(record.getName()),
             String.valueOf(record.getGender()),
              String.valueOf( record.getStartDate() ), String.valueOf( record.getAddress()),
         String.valueOf( record.getNatInsNo()),
         String.valueOf( record.getPhone()),
             String.valueOf( record.getID() ),
               String.valueOf( record.getDateOfBirth() ),
         String.valueOf( record.getSalary() ) };
         //display record contents
         userInterface.setFieldValues(values);
         //display record content
    ///////////////////////////////////from read end
    private void SaveLocation()
          // display file dialog, so user can choose file to open
          JFileChooser fileChooser = new JFileChooser();
          fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
          int result = fileChooser.showSaveDialog( this );
          // if user clicked Cancel button on dialog, return
          if ( result == JFileChooser.CANCEL_OPTION )
             return;
          File fileName = fileChooser.getSelectedFile(); // get selected file
          // display error if invalid
          if ( fileName == null || fileName.getName().equals( "" ) )
             JOptionPane.showMessageDialog( this, "Invalid File Name",
                "Invalid File Name", JOptionPane.ERROR_MESSAGE );
          else {
             // open file
             try {
                output = new ObjectOutputStream(
                   new FileOutputStream( fileName ) );
                SaveAs.setEnabled( false );
                SaveToFile.setEnabled( true );
              Exit.setEnabled( true );
             // process exceptions from opening file
             catch ( IOException ioException ) {
                JOptionPane.showMessageDialog( this, "Error Opening File",
                   "Error", JOptionPane.ERROR_MESSAGE );
          } // end else
       } // end method openFile
       // close file and terminate application
    private void closeFile()
          // close file
          try {
              //you want to cycle through each recordand add them to store here.
                                            int storeSize = store.getCount();
                                            for (int i = 0; i<storeSize;i++)
                                            output.writeObject(store.elementAt(i));
             output.close();
    input.close();// from read!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             System.exit( 0 );
          // process exceptions from closing file
          catch( IOException ioException ) {
             JOptionPane.showMessageDialog( this, "Error closing file",
                "Error", JOptionPane.ERROR_MESSAGE );
             System.exit( 1 );
       } // end method closeFile
       // add record to file
       public void addRecord()
          int employeeNumber = 0;
          String fieldValues[] = userInterface.getFieldValues();
          // if account field value is not empty
          if ( ! fieldValues[ BankUI.IDNUMBER ].equals( "" ) ) {
             // output values to file
             try {
                employeeNumber = Integer.parseInt(
                   fieldValues[ BankUI.IDNUMBER ] );
                        String dob = fieldValues[ BankUI.DOB ];
                        String[] dateofBirth = dob.split ("-"); // what used to put between number chnage to /
                        String sDate = fieldValues[ BankUI.START ];
                        String[] startDate = sDate.split ("-");
                        String sex = fieldValues[ BankUI.GENDER ];
                        char gender = (sex.charAt(0)); // check if m or f prob check in employee
    if ( employeeNumber >= 0 ) {
                  /* create new record =String name, char gender, Date dob, String add, String nin, String phone, String id, Date start, float salary*/
                    record  = new Employee(
                    fieldValues[ BankUI.NAME ],
                        gender,
                    new Date(     Integer.parseInt(dateofBirth[0]),
                              Integer.parseInt(dateofBirth[1]),
                              Integer.parseInt(dateofBirth[2])),
                        fieldValues[ BankUI.ADDRESS ],
                        fieldValues[ BankUI.NATINTNO ],
                        fieldValues[ BankUI.PHONE ],
                        fieldValues[ BankUI.IDNUMBER ],
              new Date(     Integer.parseInt(startDate[0]),
                              Integer.parseInt(startDate[1]),
                              Integer.parseInt(startDate[2])),
              Float.parseFloat( fieldValues[ BankUI.SALARY ] ));
                        if (!store.isFull())
                             store.add(record);
                        else
                        JOptionPane.showMessageDialog( this, "The Store is full you cannot add\n"+
                         "anymore employees. \nPlease Save Current File and Create a New File." );
                             System.out.println("Store full");
                        store.displayAll();
                        System.out.println("Count is " + store.getCount());
                                  // output record and flush buffer
                                  //output.writeObject( record );
                   output.flush();
                else
                    JOptionPane.showMessageDialog( this,
                       "Account number must be greater than 0",
                       "Bad account number", JOptionPane.ERROR_MESSAGE );
                // clear textfields
                userInterface.clearFields();
             } // end try
             // process invalid account number or balance format
             catch ( NumberFormatException formatException ) {
                JOptionPane.showMessageDialog( this,
                   "Bad ID number, Date or Salary", "Invalid Number Format",
                   JOptionPane.ERROR_MESSAGE );
             // process exceptions from file output
             catch ( ArrayIndexOutOfBoundsException ArrayException ) {
                 JOptionPane.showMessageDialog( this, "Error with Start Date or Date of Birth\nPlease enter like: 01-01-2001",
                    "IO Exception", JOptionPane.ERROR_MESSAGE );
                      // process exceptions from file output
             catch ( IOException ioException ) {
                 JOptionPane.showMessageDialog( this, "Error writing to file",
                    "IO Exception", JOptionPane.ERROR_MESSAGE );
                closeFile();
          } // end if
       } // end method addRecord
       public static void main( String args[] )
          new testing();
    } // end class CreateSequentialFile

    Sure you can read and write at the same time. But normally you would be reading from one place and writing to another place.
    I rather regret avoiding the OP's earlier post asking how to combine two classes. I looked at the two classes posted and realized the best thing to do was actually to break them into more classes. But I also realized it was going to be a big job explaining why and how, and I just don't have the patience for that sort of thing.
    So now we have a Big Ball Of Tar&trade; and I feel partly responsible.

  • Basic Binary File Does not Read Unless Placed into Exact Format it originated?

    Ok, check this out.  This just does not make any sense to me.  First, you'll need to run it and create the two files.  You're going to get an error at the close.  Now...here's what doesn't make any sense to me.  If you enable the disabled diagram and read that same file, you can look at how the file is being read and the data interpreted.  How is that any different and not causing an error?  I took the U8 and changed it back to its original Boolean Array[8] format and received no error.  Which means the data was read as a U8 at some point.  But...for whatever reason, cannot be read and displayed as a U8.  What's up with that?  What am I not understanding?
    Remember, code does exactly what you tell it.
    Solved!
    Go to Solution.
    Attachments:
    Binary File Issue.vi ‏23 KB

    DailyDose wrote:
    Huh....no read and write.  Either read or write.  Gotcha.
    Not quite.  It is a matter of where the file pointer is.
    The file pointer is what location in the file will be read from or written to, depending on what you do next.  When you write to a file, the file pointer is set to be directly after what you just wrote.  So when you write a new file, the file pointer is at the end of the file.  So when you try to do a read when the file pointer is at the end of the file, an attempt of a read at the end of the file happens.  But there is nothing left for it to read.  Therefore you get an End Of File error.
    So if you just added a Set File Position to set the file pointer to the start of the file, you can read your byte with no error.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Binary File Issue_BD.png ‏25 KB

  • Read Measurement file does not read the first channel of my TDMS file

    When I try to read a TDMS file with the Read Measurement File express VI, the first channel of the data is not there.  When I open the file up in excel the channel exists

    Even I have the same doubt  regarding Labview plss help me reading the Excel file from 23rd row and the graph should be drawn between 1st column and 8th column ,  from 23rd row . Here is the sample data.
    Attachments:
    Book1.xlsx ‏204 KB

  • FILE ADAPTER NOT READING FILE.

    HI, GUYS.
    I'M USING A FILE ADAPTER TO READ A FILE THAT HAVE 4 REGISTERS AND EACH REGISTER ONLY HAS ONE FIELD THAT IS NUMBER TYPE.
    I CREATE THE FILE ADAPTER, AND I LET BPEL TO CREATE THE SCHEMA. THE IDE CALLS THES FIELD "C1". I ALSO CONFIGURE THAT THE FILE THAT MUST RAD IS THE PATTERN "*.TXT" AND EVERY 5 SECONDS.
    THEN A CREATE A RECEIVE ACTIVITY THAT RECEIVES WHAT WAS READ FROM THE FILE ADAPTER IN A VARIABLE.
    THEN I CREATE AN ASSIGN ACTIVITY AND I ASSIGN THE VALUE FROM THE RECEIVE ACTIVITY VARIABLE TO A NUMBER VARIABLE THAT IS THE INPUT OF A WEB SERVICE.
    THEN I DEPLOY THE BPEL, AND I INITIATE IT, BUT I GOT AN ERROR THAT SAYS THAT THE FIELD "C1" IS EMPTY. SO LOOKS LIKE THE FILE ADAPTER IS NOT READING THE FILE. I WOULD THANK ANY HELP THAT YOU CAN BRING ME.

    caps off
    You're sure the interface of the fileadapter (client partnerlink) is the same as your data-file which needs to be picked up?
    can you paste the content of the file and the content of the xsd of the process.

  • File adapter not reading file suddenly

    Hi,
    My File to IDOC scenario was working properly. Suddenly the file adapter is not picking the file from the location. I have not changed any code. I checked all users, are in unlocked mode only. The log file throws error. Let me know any solution to resolve this
    ========
    1.5#001A4B4C508E007400000577000019F40004558D5E8AFB9D#1219965571787#/Applications/ExchangeInfrastructure/AdapterFramework/Services/Trex##com.sap.aii.af.service.trex.impl.Util.Util: getIndex()#J2EE_GUEST#0####02305f1074b511ddaa1a001a4b4c508e#SAPEngine_Application_Thread[impl:3]_27##0#0#Error#1#com.sap.aii.af.service.trex.impl.Util#Java###SLDException couldn't get the SLD instance name. Therefore the index ID couldn't be inititialized. - Message: ; To-String: .#2#Could not read SLD instance name, due to: undefSldAccessor#com.sap.aii.af.service.sld.SLDException: Could not read SLD instance name, due to: undefSldAccessor#
    #1.5#001A4B4C508E007400000579000019F40004558D5E8AFCB3#1219965571787#/Applications/ExchangeInfrastructure/AdapterFramework/Services/Trex##com.sap.aii.af.service.trex.TrexManager.TrexManager: getTrexConfiguration()#J2EE_GUEST#0####02305f1074b511ddaa1a001a4b4c508e#SAPEngine_Application_Thread[impl:3]_27##0#0#Error#1#com.sap.aii.af.service.trex.TrexManager#Java###TrexException: thrown by any problem related to the DataAccess: Message: .#1#Class: com.sap.aii.af.service.trex.TrexException : SLDException in Method: Util: getIndex(). Couldn't get the SLD instance name. Therefore the index ID couldn't be inititialized. - Message: Could not read SLD instance name, due to: undefSldAccessor; To-String: com.sap.aii.af.service.sld.SLDException: Could not read SLD instance name, due to: undefSldAccessor#
    #1.5#001A4B4C508E00740000057B000019F40004558D5E8AFDE1#1219965571787#/Applications/ExchangeInfrastructure/AdapterFramework/Services/Trex##com.sap.aii.af.service.trex.TrexScheduler.TrexScheduler: run()#J2EE_GUEST#0####02305f1074b511ddaa1a001a4b4c508e#SAPEngine_Application_Thread[impl:3]_27##0#0#Error#1#com.sap.aii.af.service.trex.TrexScheduler#Java###TrexException: thrown by any problem related to the Trex processing. Message: .#1#Class: com.sap.aii.af.service.trex.TrexException : TrexException in Method: TrexManager: getTrexConfiguration(). Thrown by any problem related to the DataAccess. Message: Class: com.sap.aii.af.service.trex.TrexException : SLDException in Method: Util: getIndex(). Couldn't get the SLD instance name. Therefore the index ID couldn't be inititialized. - Message: Could not read SLD instance name, due to: undefSldAccessor; To-String: com.sap.aii.af.service.sld.SLDException: Could not read SLD instance name, due to: undefSldAccessor#
    ========

    Hi,
    1)Stop and start the Communication Channels.
    2) Activate the scenario.
    3) If u r using FTP may be ur credentials wereexpired.check the credentials.
    "Award Points if helpful"
    Regards,
    jayasimha

  • Sender file is not read all the records

    Hi Experts,
    we got file to file scenario in production, sender file adapter did not read whole file, it did pick up some of the records only insted of whole file.
    Can anyone please suggest me why sender file adapter pick some of the records only.
    Kind Regards,
    Praveen.

    Praveen
    Try increasing the value for parameter Msecs to Wait Before Modification Check  .Ideally this parameter starts polling once your standard poll is over and checks if file size has changed. Incase its changed it further polls and keeps doing so until file size remains constant(meaning file modification is over).
    Did you try out the other alternative? Using a script to place the processed files to a separate folder and pointing your fileadapter to the same.
    Or
    As fariha suggested you can check the application responsible for putting the file in the server location. Giving it a seperate name as long as its processed like *.tmp or something and you can use exclusion mask in sender file adapter to avoid processing of the *.tmp file.
    Regards
    Soumen...

  • Small size file can not read correctly on other linux

    Hi, I am running archlinux 0.8 on my laptop, and there is another linux runs kernel version 2.6.20 with root filesystem of debian v3.1.
    I wrote a shell script which reads a small, 49 bytes, only 1 line conf file on my archlinux, it works fine.
    But if I copy script & conf files to debian, the script can not read conf file with:
    while read f;do; echo $f; done < conf
    but `cat`,`more` commands can read it. I have to open conf file with vi on debian and do nothing but :wq rewrite it to make script working.
    Both arch & debian use ext3 file system. Could anyone tell me why? thanks.

    I think your command is wrong: it works with zsh and doesn`t work in bash. Maybe you should remove extra ';'?
    while read f;do echo $f; done < conf

Maybe you are looking for

  • I can´t open pdf-files from firefox.

    When i try to open a pdf-file from firefox nothings happens. The problem started when i downloaded Firefox version 8.0.1. In safari it works.

  • ADD form.php to my site with iWeb, possible?

    Hi, is it possible to add a form.php to muy site done with iWeb? thank you.

  • My parents have forgot they admin password

    my parents did set on parent control but they have forgot the password and my password and username will not work to get this deleted, help me!!!!!!

  • Copy/Paste of RTF text from Java to Word

    Hiya I am trying to transfer info from Java to MS-Word via the Clipboard, I have had a look and a play with the code given in the tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html But even thought it is implied t

  • Java Network Issue

    So I posted the following a few days ago: I keep seeing a Pop Up that pops up and disappears again for a split second on my screen. It's so fast, I can't tell what it is, but it looks like a warning dialog box. It pops up at random times. It doesn't