tailieunhanh - murachs Java SE 2010 phần 9
Tôi cảm thấy rằng hầu hết các nội dung trong cuốn sách này được bao phủ tốt hơn trong Scott Mitchell của trong 24 giờ, kể từ Sams, ngay cả trong một của hai sách Dummies nếu bạn là một beginer. Nếu bạn có kinh nghiệm với , bạn sẽ được phục vụ tốt hơn tại O'Reilly của | Chapter 19 How to work with text and binary files 653 Common methods of the DataOutput interface Method Throws Description writeBoolean boolean lOException Writes a 1-byte boolean value to the output stream. writelnt int lOException Writes a 4-byte int value to the output stream. writeDouble double lOException Writes an 8-byte double value to the output stream. wri teChar int lOException Writes a 2-byte char value to the output stream. writeChars String lOException Writes a string using 2 bytes per character to the output stream. writeUTF String lOException Writes a 2-byte value for the number of bytes in the string followed by the L I E representation of the string which typically uses 1 byte per character. Methods of the DataOutputStream class Method Throws Description size 0 None Returns an int for the number of bytes written to this stream. flush 0 lOException Flushes any data that s in the buffer to the file. close 0 lOException Flushes any data that s in the buffer to the file and closes the stream. Code that writes data to a binary file write a Product object to the file 0 flush data to the file and close the output stream 0 Description Since the DataOutputStream class implements the DataOutput interface you can call any of the methods shown above from a DataOutputStream object. The writeUTF method uses the Universal Text Format UTF . Fừst this method writes a two-byte number for the number of bytes in the string. Then it writes the characters using the Universal Text Format. For most strings UTF uses one byte per character. Figure 19-13 How to write to a binary file 654 Section 5 Data access programming with Java How to connect a binary input stream to a file To create a binary input stream you can layer three streams from the Inputstream hierarchy as shown in figure 19-14. The example in this figure shows how you do that. As in all of the examples in
đang nạp các trang xem trước