Chapter 16 Files and Streams 921 classes FileInputStream, (Sri lanka web server)

Chapter 16 Files and Streams 921 classes FileInputStream, FileOutputStream, DataInputStream and DataOutputStreamand adds several other methods, including a seekthat repositions the file-position pointer (the byte number of the next byte in the file to be read or written) to any position in the file. However, class RandomAccessFile cannot read and write entire objects. Performance Tip 16.5 The process of closing and reopening a file for the purpose of positioning the file-position pointer back to the beginning of a file is a time-consuming task for the computer. If this is done frequently, it can slow the performance of your program. The program of Fig. 16.9 enables a credit manager to display the account information for those customers with zero balances (i.e., customers who do not owe the company any money), credit balances (i.e., customers to whom the company owes money) and debit balances (i.e., customers who owe the company money for goods and services received in the past). The program displays buttons that allow a credit manager to obtain credit information. The Credit balances button produces a list of accounts with credit balances. The Debit balances button produces a list of accounts with debit balances. The Zero balances button produces a list of accounts with zero balances. Records are displayed in a JTextAreacalled recordDisplayArea. The record information is collected by reading through the entire file and determining, for each record, whether it satisfies the criteria for the account type selected by the credit manager. Clicking one of the balance buttons sets variable accountType(line 274) to the clicked button s text (e.g., Zero balances) and invokes method readRecords(191 238), which loops through the file and reads every record. Line 208 of method readRecordscalls method shouldDisplay(241 259) to determine whether the current record satisfies the account type requested. If shouldDisplay returns true, the program appends the account information for the current record to the JTextArearecordDisplay. When the end- of-file marker is reached, line 219 calls method closeFileto close the file. 1 // Fig. 16.9: CreditInquiry.java 2 // This program reads a file sequentially and displays the 3 // contents in a text area based on the type of account the 4 // user requests (credit balance, debit balance or 5 // zero balance). 6 7 // Java core packages 8 import java.io.*; 9 import java.awt.*; 10 import java.awt.event.*; 11 import java.text.DecimalFormat; 12 13 // Java extension packages 14 import javax.swing.*; 15 16 // Deitel packages 17 import com.deitel.jhtp4.ch16.AccountRecord; Fig. 16.9Credit inquiry program (part 1 of 7). Fig. 16.9
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply