Archive for October, 2007

Chapter 16 Files and Streams 915 In the (Photography web hosting)

Saturday, October 6th, 2007

Chapter 16 Files and Streams 915 In the sample execution for the program of Fig. 16.6, we entered information for five accounts (see Fig. 16.7). The program does not show how the data records actually appear in the file. To verify that the file has been created successfully, in the next section we create a program to read the file. 16.5 Reading Data from a Sequential-Access File Data are stored in files so that they may be retrieved for processing when needed. The previous section demonstrated how to create a file for sequential access. In this section, we discuss how to read data sequentially from a file. The program of Fig. 16.8 reads records from a file created by the program of Fig. 16.6 and displays the contents of the records. The program opens the file for input by creating a FileInputStream object. The program specifies the name of the file to open as an argument to the FileInputStream constructor. In Fig. 16.6, we wrote objects to the file, using an ObjectOutputStreamobject. Data must be read from the file in the same format in which it was written to the file. Therefore, we use an ObjectInputStream chained to a FileInputStreamin this program. Note that the third sample screen capture shows the GUI displaying the last record in the file. Sample Data 100 Bob Jones 24.98 200 Steve Doe -345.67 300 Pam White 0.00 400 Sam Stone -42.16 500 Sue Rich 224.62 Fig. 16.7Sample data for the program of Fig. 16.6. 16. 1 // Fig. 16.8: ReadSequentialFile.java 2 // This program reads a file of objects sequentially 3 // and displays each record. 4 5 // Java core packages 6 import java.io.*; 7 import java.awt.*; 8 import java.awt.event.*; 9 10 // Java extension packages 11 import javax.swing.*; 12 13 // Deitel packages 14 import com.deitel.jhtp4.ch16.*; 15 16 public class ReadSequentialFile extends JFrame { 17 private ObjectInputStream input; Fig. 16.8Reading a sequential file (part 1 of 6). Fig. 16.8
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Zeus web server - 914 Files and Streams Chapter 16 Line 114

Friday, October 5th, 2007

914 Files and Streams Chapter 16 Line 114 retrieves the file the user selected by calling method getSelectedFile, which returns an object of type File that encapsulates information about the file (e.g., name and location), but does not represent the contents of the file. This File object does not open the file. We assign this File object to the reference fileName. As stated previously, a program opens a file by creating an object of stream class FileInputStreamor FileOutputStream. In this example, the file is to be opened for output, so the program creates a FileOutputStream. One argument is passed to the FileOutputStream s constructor a File object. Existing files opened for output are truncated all data in the file is discarded. Common Programming Error 16.1 It is a logic error to open an existing file for output when, in fact, the user wants to preserve the file. The contents of the file are discarded without warning. Class FileOutputStream provides methods for writing byte arrays and individual bytes to a file. For this program, we need to write objects to a file a capability not provided by FileOutputStream. The solution to this problem is a technique called chaining of stream objects the ability to add the services of one stream to another. To chain an ObjectOutputStream to the FileOutputStream, we pass the File- OutputStream object to the ObjectOutputStream s constructor (lines 127 128). The constructor could throw an IOException if a problem occurs during opening of the file (e.g., when a file is opened for writing on a drive with insufficient space, a read-only file is opened for writing or a nonexistent file is opened for reading). If so, the program displays a JOptionPane. If construction of the two streams does not throw an IOException, the file is open. Then, reference output can be used to write objects to the file. The program assumes data is input correctly and in the proper record number order. The user populates the JTextFields and clicks Enter to write the data to the file. The Enter button s actionPerformed method (lines 66 69) calls our method addRecord (lines 164 211) to perform the write operation. Line 188 calls method writeObject to write the record object to file. Line 189 calls method flush to ensure that any data stored in memory is written to the file immediately. When the user clicks the close box (the X in the window s top-right corner), the program calls method windowClosing (lines 82 88), which compares output to null (line 84). If output is not null, the stream is open and methods addRecord and closeFile (lines 145 161) are called. Method closeFile calls method close for output to close the file. Performance Tip 16.3 Always release resources explicitly and at the earliest possible moment at which it is determined that the resource is no longer needed. This makes the resource immediately available to be reused by your program or by another program, thus improving resource utilization. When using chained stream objects, the outermost object (the ObjectOutput- Stream in this example) should be used to close the file. Performance Tip 16.4 Explicitly close each file as soon as it is known that the program will not reference the file again. This can reduce resource usage in a program that will continue executing long after it no longer needs to be referencing a particular file. This practice also improves program clarity.
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Chapter 16 Files and Streams 913 Select location (Shared web hosting)

Friday, October 5th, 2007

Chapter 16 Files and Streams 913 Select location for file here Files and directories are displayed here BankUI graphical user interface Click Save to submit new file name to program Fig. 16.6Creating a sequential file (part 6 of 6). Fig. 16.6 Line 107 calls method showSaveDialog to display the JFileChooser dialog titled Save. Argument this specifies the JFileChooser dialog s parent window, which determines the position of the dialog on the screen. If nullis passed, the dialog is displayed in the center of the window; otherwise, the dialog is centered over the application window. When displayed, a JFileChooser dialog does not allow the user to interact with any other program window until the user closes the JFileChooser dialog by clicking Save or Cancel. Dialogs that behave in this fashion are called modal dialogs. The user selects the drive, directory and file name, then clicks Save. Method showSaveDialog returns an integer specifying which button the user clicked (Save or Cancel) to close the dialog. Line 110 tests whether the user clicked Cancel by comparing result to staticconstant CANCEL_OPTION. If so, the method returns.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

912 Files and Streams Chapter 16 169 170

Thursday, October 4th, 2007

912 Files and Streams Chapter 16 169 170 // if account field value is not empty 171 if ( ! fieldValues[ BankUI.ACCOUNT ].equals( “” ) ) { 172 173 // output values to file 174 try { 175 accountNumber = Integer.parseInt( 176 fieldValues[ BankUI.ACCOUNT ] ); 177 178 if ( accountNumber > 0 ) { 179 180 // create new record 181 record = new AccountRecord( accountNumber, 182 fieldValues[ BankUI.FIRSTNAME ], 183 fieldValues[ BankUI.LASTNAME ], 184 Double.parseDouble( 185 fieldValues[ BankUI.BALANCE ] ) ); 186 187 // output record and flush buffer 188 output.writeObject( record ); 189 output.flush(); 190 } 191 192 // clear textfields 193 userInterface.clearFields(); 194 } 195 196 // process invalid account number or balance format 197 catch ( NumberFormatException formatException ) { 198 JOptionPane.showMessageDialog( this, 199 “Bad account number or balance”, 200 “Invalid Number Format”, 201 JOptionPane.ERROR_MESSAGE ); 202 } 203 204 // process exceptions from file output 205 catch ( IOException ioException ) { 206 closeFile(); 207 } 208 209 } // end if 210 21 } // end method addRecord 21 21 // execute application; CreateSequentialFile constructor 21 // displays window 21 public static void main( String args[] ) 21 { 21 new CreateSequentialFile(); 21 } 21 220 } // end class CreateSequentialFile Fig. 16.6Creating a sequential file (part 5 of 6). Fig. 16.6
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Chapter 16 Files and Streams 911 (Ftp web hosting) 116 //

Thursday, October 4th, 2007

Chapter 16 Files and Streams 911 116 // display error if invalid 117 if ( fileName == null || 118 fileName.getName().equals( “” ) ) 119 JOptionPane.showMessageDialog( this, 120 “Invalid File Name”, “Invalid File Name”, 121 JOptionPane.ERROR_MESSAGE ); 122 123 else { 124 125 // open file 126 try { 127 output = new ObjectOutputStream( 128 new FileOutputStream( fileName ) ); 129 130 openButton.setEnabled( false ); 131 enterButton.setEnabled( true ); 132 } 133 134 // process exceptions from opening file 135 catch ( IOException ioException ) { 136 JOptionPane.showMessageDialog( this, 137 “Error Opening File”, “Error”, 138 JOptionPane.ERROR_MESSAGE ); 139 } 140 } 141 142 } // end method openFile 143 144 // close file and terminate application 145 private void closeFile() 146 { 147 // close file 148 try { 149 output.close(); 150 151 System.exit( 0 ); 152 } 153 154 // process exceptions from closing file 155 catch( IOException ioException ) { 156 JOptionPane.showMessageDialog( this, 157 “Error closing file”, “Error”, 158 JOptionPane.ERROR_MESSAGE ); 159 System.exit( 1 ); 160 } 161 } 162 163 // add record to file 164 public void addRecord() 165 { 166 int accountNumber = 0; 167 AccountRecord record; 168 String fieldValues[] = userInterface.getFieldValues(); Fig. 16.6Creating a sequential file (part 4 of 6). Fig. 16.6
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.


ringtones teen paular

Other major ringtones teen paular manufacturers (in order of market share) include Samsung (14%), Motorola (14%), Sony Ericsson (9%) and LG (7%).

ringtones tommy boy

Fixed phones of the late 20th century and later detect this AC voltage and trigger ringtones tommy boy tone electronically.

for blackberry 7290 of ringtones type

Cordless phones are standard telephones with radio handsets.

ringtones v

This is ringtones v which covers radios which could connect into the telephone network.

wake ringtone forest university

India expects to reach 500 million subscribers by end of 2010.

ringtone converter to wma

Cell sites have relatively low-power (often only one or two watts) radio transmitters which broadcast their presence and relay communications between ringtone converter to wma handsets and the switch.

your mom ringtone

Third-generation (3G) networks, which are still being deployed, began in Japan in 2001.

free in ringtone morning 4 the

com, ReCellular, and MyGreenElectronics offer to buy back and recycle free in ringtone morning 4 the s from users.

to iphone an add ringtones

Some providers allow users to create their own music tones, either with to iphone an add ringtones composer” or a sample/loop arranger (such as the MusicDJ in many Sony Ericsson phones).

ringtones wireless appalachian

In some developing countries with little “landline” telephone infrastructure, ringtones wireless appalachian use has quadrupled in ringtones wireless appalachian decade.

Web server - 910 Files and Streams Chapter 16 65 //

Thursday, October 4th, 2007

910 Files and Streams Chapter 16 65 // call addRecord when button pressed 66 public void actionPerformed( ActionEvent event ) 67 { 68 addRecord(); 69 } 70 71 } // end anonymous inner class 72 73 ); // end call to addActionListener 74 75 // register window listener to handle window closing event 76 addWindowListener( 77 78 // anonymous inner class to handle windowClosing event 79 new WindowAdapter() { 80 81 // add current record in GUI to file, then close file 82 public void windowClosing( WindowEvent event ) 83 { 84 if ( output != null ) 85 addRecord(); 86 87 closeFile(); 88 } 89 90 } // end anonymous inner class 91 92 ); // end call to addWindowListener 93 94 setSize( 300, 200 ); 95 show(); 96 97 } // end CreateSequentialFile constructor 98 99 // allow user to specify file name 100 private void openFile() 101 { 102 // display file dialog, so user can choose file to open 103 JFileChooser fileChooser = new JFileChooser(); 104 fileChooser.setFileSelectionMode( 105 JFileChooser.FILES_ONLY ); 106 107 int result = fileChooser.showSaveDialog( this ); 108 109 // if user clicked Cancel button on dialog, return 110 if ( result == JFileChooser.CANCEL_OPTION ) 111 return; 112 113 // get selected file 114 File fileName = fileChooser.getSelectedFile(); 115 Fig. 16.6Creating a sequential file (part 3 of 6). Fig. 16.6
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Web host server - Chapter 16 Files and Streams 909 13 //

Wednesday, October 3rd, 2007

Chapter 16 Files and Streams 909 13 // Deitel packages 14 import com.deitel.jhtp4.ch16.BankUI; 15 import com.deitel.jhtp4.ch16.AccountRecord; 16 17 public class CreateSequentialFile extends JFrame { 18 private ObjectOutputStream output; 19 private BankUI userInterface; 20 private JButton enterButton, openButton; 21 22 // set up GUI 23 public CreateSequentialFile() 24 { 25 super( “Creating a Sequential File of Objects” ); 26 27 // create instance of reusable user interface 28 userInterface = new BankUI( 4 ); // four textfields 29 getContentPane().add( 30 userInterface, BorderLayout.CENTER ); 31 32 // get reference to generic task button doTask1 in BankUI 33 // and configure button for use in this program 34 openButton = userInterface.getDoTask1Button(); 35 openButton.setText( “Save into File …” ); 36 37 // register listener to call openFile when button pressed 38 openButton.addActionListener( 39 40 // anonymous inner class to handle openButton event 41 new ActionListener() { 42 43 // call openFile when button pressed 44 public void actionPerformed( ActionEvent event ) 45 { 46 openFile(); 47 } 48 49 } // end anonymous inner class 50 51 ); // end call to addActionListener 52 53 // get reference to generic task button doTask2 in BankUI 54 // and configure button for use in this program 55 enterButton = userInterface.getDoTask2Button(); 56 enterButton.setText( “Enter” ); 57 enterButton.setEnabled( false ); // disable button 58 59 // register listener to call addRecord when button pressed 60 enterButton.addActionListener( 61 62 // anonymous inner class to handle enterButton event 63 new ActionListener() { 64 Fig. 16.6Creating a sequential file (part 2 of 6). Fig. 16.6
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

908 Files (Web host sites) and Streams Chapter 16 55 //

Wednesday, October 3rd, 2007

908 Files and Streams Chapter 16 55 // set last name 56 public void setLastName( String last ) 57 { 58 lastName = last; 59 } 60 61 // get last name 62 public String getLastName() 63 { 64 return lastName; 65 } 66 67 // set balance 68 public void setBalance( double bal ) 69 { 70 balance = bal; 71 } 72 73 // get balance 74 public double getBalance() 75 { 76 return balance; 77 } 78 79 } // end class AccountRecord Fig. 16.5 Class AccountRecordmaintains information for one account (part 3 of 3). Now, let us discuss the code that creates the sequential-access file (Fig. 16.6). In this example, we introduce class JFileChooser(package javax.swing) for selecting files (as on the second screen in Fig. 16.6). Line 103 constructs a JFileChooserinstance and assigns it to reference fileChooser. Lines 104 105 call method setFileSelectionModeto specify what the user can select from the fileChooser. For this program, we use JFileChooserstaticconstant FILES_ONLYto indicate that only files can be selected. Other static constants include FILES_AND_DIRECTORIES and DIRECTORIES_ONLY. 1 // Fig. 16.6: CreateSequentialFile.java 2 // Demonstrating object output with class ObjectOutputStream. 3 // The objects are written sequentially to a file. 4 5 // Java core packages 6 import java.io.*; 7 import java.awt.*; 8 import java.awt.event.*; 9 10 // Java extension packages 11 import javax.swing.*; 12 Fig. 16.6Creating a sequential file (part 1 of 6). Fig. 16.6
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Chapter 16 Files and Streams 907 4 5 (Web design programs)

Tuesday, October 2nd, 2007

Chapter 16 Files and Streams 907 4 5 // Java core packages 6 import java.io.Serializable; 7 8 public class AccountRecord implements Serializable { 9 private int account; 10 private String firstName; 11 private String lastName; 12 private double balance; 13 14 // no-argument constructor calls other constructor with 15 // default values 16 public AccountRecord() 17 { 18 this( 0, “”, “”, 0.0 ); 19 } 20 21 // initialize a record 22 public AccountRecord( int acct, String first, 23 String last, double bal ) 24 { 25 setAccount( acct ); 26 setFirstName( first ); 27 setLastName( last ); 28 setBalance( bal ); 29 } 30 31 // set account number 32 public void setAccount( int acct ) 33 { 34 account = acct; 35 } 36 37 // get account number 38 public int getAccount() 39 { 40 return account; 41 } 42 43 // set first name 44 public void setFirstName( String first ) 45 { 46 firstName = first; 47 } 48 49 // get first name 50 public String getFirstName() 51 { 52 return firstName; 53 } 54 Fig. 16.5 Class AccountRecordmaintains information for one account (part 2 of 3).
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

906 Files and Streams (Web site designers) Chapter 16 100 }

Tuesday, October 2nd, 2007

906 Files and Streams Chapter 16 100 } 101 102 // set text field values; throw IllegalArgumentException if 103 // incorrect number of Strings in argument 104 public void setFieldValues( String strings[] ) 105 throws IllegalArgumentException 106 { 107 if ( strings.length != size ) 108 throw new IllegalArgumentException( “There must be ” + 109 size + ” Strings in the array” ); 110 111 for ( int count = 0; count < size; count++ ) 112 fields[ count ].setText( strings[ count ] ); 113 } 114 115 // get array of Strings with current text field contents 116 public String[] getFieldValues() 117 { 118 String values[] = new String[ size ]; 119 120 for ( int count = 0; count < size; count++ ) 121 values[ count ] = fields[ count ].getText(); 122 123 return values; 124 } 125 126 } // end class BankUI Fig. 16.4 BankUIcontains a reusable GUI for several programs (part 3 of 3). Class AccountRecord (Fig. 16.5) implements interface Serializable, which allows objects of AccountRecord to be used with ObjectInputStreams and ObjectOutputStreams. Interface Serializable is known as a tagging interface. Such an interface contains no methods. A class that implements this interface is tagged as being a Serializable object, which is important because an ObjectOutput- Stream will not output an object unless it is a Serializable object. In a class that implements Serializable, the programmer must ensure that every instance variable of the class is a Serializable type, or must declare particular instance variables as transient to indicate that those variables are not Serializable and they should be ignored during the serialization process. By default, all primitive type variables are transient. For non-primitive types, you must check the definition of the class (and possibly its superclasses) to ensure that the type is Serializable. Class AccountRecord contains privatedata members account, firstName, lastNameand balance. This class also provides public get and set methods for accessing the private data members. 1 // Fig. 16.5: AccountRecord.java 2 // A class that represents one record of information. 3 package com.deitel.jhtp4.ch16; Fig. 16.5 Class AccountRecordmaintains information for one account (part 1 of 3).
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.