Anonymous web server - Chapter 16 Files and Streams 925 177 }
Thursday, October 11th, 2007Chapter 16 Files and Streams 925 177 } 178 179 // process exception from closing file 180 catch ( IOException ioException ) { 181 JOptionPane.showMessageDialog( this, 182 “Error closing file”, 183 “Error”, JOptionPane.ERROR_MESSAGE ); 184 185 System.exit( 1 ); 186 } 187 } 188 189 // read records from file and display only records of 190 // appropriate type 191 private void readRecords() 192 { 193 AccountRecord record; 194 DecimalFormat twoDigits = new DecimalFormat( “0.00″ ); 195 openFile( false ); 196 197 // read records 198 try { 199 recordDisplayArea.setText( “The accounts are:n” ); 200 201 // input the values from the file 202 while ( true ) { 203 204 // read one AccountRecord 205 record = ( AccountRecord ) input.readObject(); 206 207 // if proper acount type, display record 208 if ( shouldDisplay( record.getBalance() ) ) 209 recordDisplayArea.append( record.getAccount() + 210 “t” + record.getFirstName() + “t” + 211 record.getLastName() + “t” + 212 twoDigits.format( record.getBalance() ) + 213 “n” ); 214 } 215 } 216 217 // close file when end-of-file reached 218 catch ( EOFException eofException ) { 219 closeFile(); 220 } 221 222 // display error if cannot read object 223 // because class not found 224 catch ( ClassNotFoundException classNotFound ) { 225 JOptionPane.showMessageDialog( this, 226 “Unable to create object”, 227 “Class Not Found”, JOptionPane.ERROR_MESSAGE ); 228 } 229 Fig. 16.9Credit inquiry program (part 5 of 7). Fig. 16.9
Check Tomcat Web Hosting services for best quality webspace to host your web application.