Lecture An Introduction to Object-Oriented Programming with Java (4/e): Chapter 12 - C. Thomas Wu

Chapter 12 - File input and output. After you have read and studied this chapter, you should be able to: Include a JFileChooser object in your program to let the user specify a file; write bytes to a file and read them back from the file, using FileOutputStream and FileInputStream; write values of primitive data types to a file and read them back from the file, using DataOutputStream and DataInputStream;. | Chapter 12 File Input and Output 4th Ed Chapter N - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12 Objectives After you have read and studied this chapter, you should be able to Include a JFileChooser object in your program to let the user specify a file. Write bytes to a file and read them back from the file, using FileOutputStream and FileInputStream. Write values of primitive data types to a file and read them back from the file, using DataOutputStream and DataInputStream. Write text data to a file and read them back from the file, using PrintWriter and BufferedReader Read a text file using Scanner Write objects to a file and read them back from the file, using ObjectOutputStream and ObjectInputStream 4th Ed Chapter N - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The File Class To operate on a file, we must first create a File object (from ). File inFile = new File(“”); File inFile = new File (“C:/SamplePrograms/”); Opens the file in the current directory. Opens the file in the directory C:\SamplePrograms using the generic file separator / and providing the full pathname. 4th Ed Chapter N - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. When a program that manipulates a large amount of data practical, we must save the data to a file. If we don’t, then the user must reenter the same data every time he or she runs the program because any data used by the program will be erased from the main memory at program termination. If the data were saved, then the program can read them back from the file and rebuild the information so the user can work on the data without reentering them. In this chapter you will learn how to save data to and read data from a file. We call the action of saving data to a file file output and the action of reading data from a file file input. Note: The statements new . | Chapter 12 File Input and Output 4th Ed Chapter N - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12 Objectives After you have read and studied this chapter, you should be able to Include a JFileChooser object in your program to let the user specify a file. Write bytes to a file and read them back from the file, using FileOutputStream and FileInputStream. Write values of primitive data types to a file and read them back from the file, using DataOutputStream and DataInputStream. Write text data to a file and read them back from the file, using PrintWriter and BufferedReader Read a text file using Scanner Write objects to a file and read them back from the file, using ObjectOutputStream and ObjectInputStream 4th Ed Chapter N - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The File Class To operate on a file, we must first create a File object (from ). File inFile = new File(“”); File

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
476    17    1    27-11-2024
12    25    1    27-11-2024
Đã 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.