Java RandomAccessFile , Only finds the first entry -


When my program reads from a random file, it will only get the first file or file with the following account number (this A banking program) after that I got an error reading the IO exception

  with the private RandomAccessFile input; // Random Aecess file input stream private record data; Public Stable JFrame Frame = New JFrame (); Public CredRead () // Constructor CredRead created {// Try File /} // output stream object declare and associate it to file / file.dat input = new RandomAccessFile ("UnionDB.dat", "rw") Do; } Hold (IOException E) {// If an error displays a message on the screen System.err.println ("The file did not open correctly \ n" + e.toString ()); // Program system ends due to error. exit (1); } Data = new record (); Setpriffer Size (new dimension (650, 400)); frame.setSize (getPreferredSize ()); // frame size frame.Setlinersillettau (empty); Frame.setLayout (new grid layout (7, 2)); // Grid layout set / * GUI component * / frame.ed (new label ("Enter account number and click on enter"); Account_num = new textfield (); Frame.add (ACCOUNT_NUM); account_num.addActionListener (this); frame.add (new label ("first name")); First_name = new textfield (20); First_name.setEditable (wrong); Frame.add (first_name); Frame.add (new label ("last name")); Last_name = new textfield (20); Last_name.setEditable (wrong); frame.add (last_name); Frame.ed (new label ("available fund")); Balance = new textfield (20); Balance.setEditable (wrong); frame.add (balance); frame.add (new label ("overdraft limit")); Overdraft = new textfield (20); Overdraft.setEditable (wrong); Frame.add (overdraft); Enter = New button ("Enter"); Enter.addActionListener (this); frame.add (login); Did = new button ("click to exit"); Done.addActionListener (this); frame.add (done); SetVisible (true); // GUI component defined as visible for program} Public Nine Read Records (Decimal Two Format = New Decimal Factor ("0.00"); Try {do {data.read (input); } While (data. GetAccount () == 0); input.seek (long) (data .getAccount () - 1) * record. ()) ;; data.write (input); account_num.setText (String.valueOf (data.getAccount ())); first_name.setText (data.getFirstName ()); last_name.setText (data.getLastName ()); balance.setText (String.valueOf (twoDigits.format (data.getBalance ()))); overdraft.setText (String.valueOf (twoDigits.format (data.getOverdraft ()))); } // Try end capture (EOFException eof) {closeFile (); } Hold (IOException E) {// If an error screen is displayed on a message System.err.println ("while reading from the error file \ n" + e.toString ()); / / Error causes the program ends System.exit (1); }} Private Zero Stop file () {try {input.close ()} // System.exit (1); } Hold (IOException e) {// If an error displays a message on the screen System.err.println ("Error in closing the file \ n" + e.toString ()); // System.exit (1); }} Public Zero Functionality (Action Event e) {if (e.getSource () == enter) readRecord (); Else if (e.getSource () == done) frame.dispose (); Else frame.add (new textfield ("not found on account database")); closeFile (); } Public stable zero major (string algos []) {new crude read (); }   

}

My guess is that

data.getAccount ()! = 0

And so your loop only executes once, because you did it ... while ();

Try adding something to your debug in code and make sure that the data. Account () is equal.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -