Java All-in-One Desk Reference For Dummies phần 9

Bạn cũng muốn để thiết lập các lĩnh vực neo để chỉ ra nơi bạn muốn các thành phần đặt nếu nó không điền vào các tế bào hoặc các tế bào được phân bổ cho nó. Sau đó, bạn có thể gọi phương thức để bổ sung thêm lĩnh vực văn bản tên cho bảng điều khiển: | 686 Writing Character Streams 75 The Movie class is a private inner class that defines the movie objects. To keep the class simple it uses public fields and a single constructor that initializes the fields. Writing Character Streams The usual way to write data to a text file is to use the Printwriter class which as luck has it you re already familiar with It s the same class that provides the print and println methods used to write console output. As a result the only real trick to writing output to a text file is figuring out how to connect a print writer to a text file. To do that you work with three classes FileWriter The Filewriter class connects to a File object but provides only rudimentary writing ability. BufferedWriter This class connects to a Filewriter and provides output buffering. Without the buffer data is written to disk one character at a time. This class lets the program accumulate data in a buffer and writes the data only when the buffer is filled up or when the program requests that the data be written. Printwriter This class connects to a Writer which can be a BufferedWriter a Filewriter or any other object that extends the abstract writer class. Most often you connect this class to a BufferedWriter. The Printwriter class is the only one of these classes whose methods you usually use when you write data to a file. Table 2-2 lists the most important constructors and methods of this class. Table 2-2 The Printwriter BufferedWriter and FileWriter Classes Constructors Description Printwriter writer out Creates a print writer for the specified output writer. Printwriter writer out Creates a print writer for the specified output writer. If boolean flush the second parameter is true the buffer is automati- cally flushed whenever the println method is called. BufferedWriter Writer Creates a buffered writer from the specified writer. out Typically you pass this constructor a Filewriter object. FileWriter File file Creates a file writer from the specified

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.