Lecture An introduction to Object-Oriented Programming with Java - 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 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. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12 Objectives, cont. After you have read and studied this chapter, you should be able to Write text data to a file and read them back from the file, using PrintWriter and BufferedReader. Write objects to a file and read them back from the file, using ObjectOutputStream and ObjectInputStream. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. File and JFileChooser Objects The action of saving, or writing, data to a file is called file output. The action of reading data from a file is called file input. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. File and JFileChooser Objects Before we can read data from a file, we must create a File object and associate it to the file from which we wish to read. We do this by calling a File constructor: File inFile = newFile(“”); ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. File and JFileChooser Objects This approach assumes that the file is located in the current directory. Otherwise, we must specify the path and file name when we call the constructor: File inFile = new File(“C:/JavaPrograms”,””); The formatting of the path name and file name is different for different operating systems. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Fig. Directory structure used for the examples in this section. We assume the Windows environment. ©TheMcGraw-Hill . | Chapter 12 File Input and Output 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. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 12 Objectives, cont. After you have read and studied this chapter, you should be able to Write text data to a file and read them back from the file, using PrintWriter and BufferedReader. Write objects to a file and read them back from the file, using ObjectOutputStream and ObjectInputStream. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. File and JFileChooser Objects The action of saving, or writing, data to a file is called file output. The

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.