Java programming things 84--io Introduction

Source: Internet
Author: User

Java programming things 84--io Introduction

Chen yuefeng

From: http://blog.csdn.net/mailbomb

Chapter 1 I/O processing

I/O (input/output) is short for input and output. All input/output-related technologies in Java are Io processing technologies, for example, reading and writing files and sending network data.

In fact, the main function of the entire computer is I/O. The user uses the mouse, keyboard and other input devices to input data to the program, and the program performs some logic processing, then, the processing result is displayed on the display and other output devices in a certain form.

I/O processing technology is the basis for implementing file operations, memory operations, console input, and network programming in Java. However, due to the design of I/O technology, it also makes the I/O processing technology more difficult and requires a lot of effort to learn.

11.1 I/O Introduction

Io is short for input and output. In actual use, input and output are oriented. Just as in reality, two people borrow money from each other. For example, a borrows money from B, which is borrowed from a, and B. Therefore, when talking about input and output in a program, you also need to clearly distinguish the relative content.

In the program, both input and output are relative to the current program. For example, reading the content of a configuration file from the hard disk to the program is equivalent to inputting the content of the file into the program, therefore, the input corresponds to "read", and the content stored in the program to the hard disk is equivalent to outputting the content of the file to the outside of the program, so the output corresponds to "write. Familiarizing yourself with the ing between input and output will help you learn the subsequent content.

In Java, the concept of input and output is much more extensive than that of input and output in other languages, including not only reading and writing files, but also sending network data, i/O can even read/write memory data and receive console data.

In order to make the input and output structures uniform and facilitate programmers to use io-related classes, a new concept-stream (Stream) was introduced in the IO class design of Java ).

Many types of operations are required during I/O operations, such as files, memory, and network connections. These operations are called data sources ), different data sources are processed in different ways. If the data is directly handed over to the programmer for processing, it is complicated for the programmer.

Therefore, when reading data in all I/O classes, JDK API converts the data from the data source to a fixed data sequence. When writing data, write the data to the data sequence in a certain format. The jdk api writes the data in the data sequence to the corresponding data source. In this way, the system completes complex data conversion and different transformations between different data sources, thus simplifying coding for programmers.

I/O's design is the same as the water supply and drainage system design in the city. When water is supplied, different types of water sources include river water, lake water, and groundwater, the water supply company converts the water source to the corresponding water flow. In the design of the drainage system, you only need to discharge the sewage into the sewage pipeline. As to how the sewage is processed, you do not need to care about it. This simplifies the treatment of domestic water.

In Io design, this data sequence is called stream ). By using the concept of stream, programmers only need to establish different streams for different data sources, and the complexity of implementation of the bottom layer is completed by the system, so that programmers do not have to have a deep understanding of the read and write methods for each data source, thus reducing the complexity of Io programming.

During the entire Io process, the data reading process is divided into two steps: 1. Convert the content of the data source to the stream structure. This step is completed by the jdk api, programmers only need to select the appropriate stream type. 2. read data from the stream. This step is completed by the programmer. The data sequence in the stream is consistent with the data storage sequence in the data source.

The Data Writing Process is also divided into two steps: 1. A special stream structure established to connect to the specified data source, which is completed by jdk api, programmers only need to select the appropriate stream type. 2. Write Data to the stream in a certain format. This step is completed by the programmer. The data in the stream is stored in the data source order. Finally, when the data is written to the stream, you can write the data in the stream to the data source in a certain way, or when the stream is closed, the system will automatically write the data in the stream to the data source.

In this way, the most complex and data source operations are completed by the jdk api during the entire Io class design. When programmers program, they only need to select the appropriate stream type, then read and write.

Like the actual structure, the stream in Io is also oriented. The stream used for reading is called the input stream, and the stream used for writing is called the output stream ). When reading and writing, you need to select the appropriate stream object for operation.

The stream structure is as follows:

 

Read data streams

 

 

 


Write Data Stream

Because the Java language uses object-oriented technology, each stream type is represented by a special class during implementation, instead, the logic for reading or writing data sources of this type is encapsulated inside the class. When the programmer creates the corresponding object, the stream structure is completed, subsequent Io operations only need to read or write the data inside the stream object. In this way, Io operations are relatively simple and easy for Java programmers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.