0 Replies Latest reply: Mar 23, 2008 1:20 PM by 800296 RSS

    Reading arrays from a file back into thier original arrays. Help

    800296
      Hi.

      Is it possible to retrieve arrays from a mirror of how you saved them?
      My example is as follows
      This is how I saved them.
      try
                {
                     for(int i=0; i < name.length; i++)
                     {
                          output.writeUTF(name);
                          output.writeUTF(surname[i]);
                          output.writeUTF(work[i]);
                          output.writeUTF(home[i]);
                          output.writeUTF(cell[i]);
                     }
                     JOptionPane.showMessageDialog(null,"Data succesfully saved to file.","Information message",JOptionPane.INFORMATION_MESSAGE);
                }
                catch(IOException io)
                {
                     System.exit(1);
                }
      And now try to get them back but I dont know how. This is not working. And it just looks silly to me. Got it off some other forum.
      And I need to keep the identifiers for each array the same as they are used throughough the program and are class variables. So In other words when I retrieve the arrays back from the file I want them to go back into the origianal arrays.
           try
                {
                     input = new DataInputStream(new FileInputStream(filename));
                }
                catch(IOException io)
                {
                     JOptionPane.showMessageDialog(null,"Could not find the correct file to read data from.","Error",JOptionPane.ERROR_MESSAGE);
                }
                try
                {
                     for(int i=0; i< name.length; i++)
                     {
                          name[i]=input.readUTF();
                          surname[i]=input.readUTF();
                          work[i]=input.readUTF();
                          home[i]=input.readUTF();
                cell[i]=input.readUTF();
                }
                }
                catch(IOException io)
                {
                }