TAILIEUCHUNG - Lecture Introduction to programming with Java - Chapter 15: Files

This chapter presents the following content: I/O basics, file I/O classes, file I/O basic operations, text file output, text file input, HTML file generator, text format versus binary format, binary I/O, object I/O. | Chapter 15 – Files I/O basics File I/O Classes File I/O Basic Operations Text File Output PrintWriter import Statement with a * Text File Input Scanner, FileReader HTML File Generator Text Format Versus Binary Format Binary I/O Output with: DataOutputStream, FileOutputStream Input with: DataInputStream, FileInputStream Object I/O Output with: ObjectOutputStream, FileOutputStream Input with: ObjectInputStream, FileInputStream 1 I/O Basics So far, all input has come from the keyboard and all output has been to the console window. Keyboard and console input/output (I/O) is temporary, not permanent. For permanent I/O, use files. Benefit of reading input from a file: Allows input to be reused without having to re-enter the input via the keyboard. Benefits of saving output to a file: Allows output to be re-viewed without having to rerun the program. Allows program chaining where the output of one program is used as the input for another program. 2 File I/O Classes For programs that manipulate files, you'll need to use several pre-built classes from the Java API library. The Java API is organized as a hierarchy of packages where each package contains a group of classes. Here's the file I/O portion of the Java API library: 3 File I/O Classes There are lots of classes that deal with file I/O, and there's overlap with some of those classes. In other words, some classes handle the same sort of file operation(s). The book covers the file I/O classes that are the easiest to use. Here are the file I/O classes that the book covers: If you want to write text to a file, use the PrintWriter class. If you want to read text from a file, use the Scanner and FileReader classes. If you want to write objects to a file, use the ObjectOutputStream and FileOutputStream classes. If you want to read objects from a file, use the ObjectInputStream and FileInputStream classes. When you write "text" to a file, you store the text as characters where each character is represented by its

Đã 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.