Chapter 16 Files and Streams (Cpanel web hosting) 895 Outline 16.1

Chapter 16 Files and Streams 895 Outline 16.1 Introduction 16.2 Data Hierarchy 16.3 Files and Streams 16.4 Creating a Sequential-Access File 16.5 Reading Data from a Sequential-Access File 16.6 Updating Sequential-Access Files 16.7 Random-Access Files 16.8 Creating a Random-Access File 16.9 Writing Data Randomly to a Random-Access File 16.10 Reading Data Sequentially from a Random-Access File 16.11 Example: A Transaction-Processing Program 16.12 Class File Summary Terminology Self-Review Exercises Answers to Self-Review Exercises Exercises 16.1 Introduction Storage of data in variables and arrays is temporary the data is lost when a local variable goes out of scope or when the program terminates. Programs use files for long-term retention of large amounts of data, even after programs that create the data terminate. We refer to data maintained in files as persistent data, because the data exists beyond the duration of program execution. Computers store files on secondary storage devices such as magnetic disks, optical disks and magnetic tapes. In this chapter, we explain how Java programs create, update and process data files. We consider both sequential-access files and random-access files and discuss typical applications for each. File processing is one of the most important capabilities a language must have to support commercial applications that typically process massive amounts of persistent data. In this chapter, we discuss Java s powerful file-processing and stream input/output features. File processing is a subset of Java s stream-processing capabilities that enable a program to read and write bytes in memory, in files and over network connections. We have two goals in this chapter to introduce file-processing paradigms and to provide the reader with sufficient stream-processing capabilities to support the networking features introduced in Chapter 17. Software Engineering Observation 16.1 It would be dangerous to enable applets arriving from anywhere on the World Wide Web to be able to read and write files on the client system. By default, Web browsers prevent applets from performing file processing on the client system. Therefore, file-processing programs generally are implemented as Java applications. 16.2 Data Hierarchy Ultimately, a computer processes all data items as combinations of zeros and ones, because it is simple and economical for engineers to build electronic devices that can assume two stable states one state represents 0, the other state represents 1. It is remarkable that the
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply