Detailed introduction to the use of Java input and output streams

1. What is IO@H_403_2 @

I / O operation in Java mainly refers to input and output operation using Java All Java I / O mechanisms are based on data streams for input and output. These data streams represent the flow sequence of character or byte data@ H_ 403_ 2@Java I / O flow provides a standard way to read and write data. Any object representing a data source in Java will provide a method to read and write its data in the form of data flow@ H_ 403_ 2@

Java. IO is the main software package for most data flow oriented input / output classes@ H_ 403_ 2 @ in addition, Java also supports block transfer in the core library Java NiO uses block io@ H_ 403_ 2@

The advantage of streaming IO is simple and easy to use, but the disadvantage is low efficiency. Block IO is very efficient, but programming is complex. Java IO model: the design of Java IO model is very excellent. It uses decorator mode to divide streams according to functions. You can dynamically assemble these streams to obtain the functions you need. For example, if you need a buffered file input stream, you should use a combination of FileInputStream and bufferedinputstream.

@H_ 403_ 2@ data flow is a collection of continuous data, just like the water flow in a water pipe. Water is supplied bit by bit at one end of the water pipe, and a continuous water flow is seen at the other end of the water pipe. The data writer can write data to the data flow pipeline section by section, and these data sections will form a long data flow in sequence. For the data reader, you can't see the segmentation of the data stream during writing. You can read any length of data each time, but you can only read the previous data first and then the subsequent data. Whether the data is written multiple times or as a whole, the effect of reading is exactly the same@ H_ 403_ 2@ @H_ 403_ 2@@H_ 403_ 2@

@H_ 403_ 2 @ "a stream is the source or destination of data stored in a disk or other peripheral device."@ H_ 403_ 2@

There are three ways to store data on the computer, one is external memory, one is memory, and the other is cache. For example, the hard disk, disk and U disk on the computer are external memory. There is a memory module on the computer, and the cache is in the CPU. The storage capacity of external memory is the largest, followed by memory and cache, but the reading of external memory data is the slowest, followed by memory and cache. Here is a summary of reading data from external memory to memory and writing data from memory to external memory. For the understanding of memory and external memory, we can simply understand it as a container, that is, external memory is a container and memory is another container. So how to read the data in the external storage container into the memory container and how to store the data in the memory container into external storage@ H_ 403_ 2@

In the Java class library, the content of IO is huge because it involves a wide range of fields: @ h_ 403_ 2@@H_ 403_ 2@

Standard I / O, @ h_ 403_ 2@@H_ 403_ 2@@H_ 403_ 2 @ file operation, @ h_ 403_ 2@@H_ 403_ 2 @ network @ h_ 403_ 2@@H_ 403_ Data stream, character stream, object stream, zip file stream on @ 2, @ h_ 403_ 2@@H_ 403_ 2@@H_ 403_ 2@java The input-output abstraction is called stream @ H_ 403_ 2@, like a water pipe, connects the two containers. The input stream that flushes the data into the external memory and reads it into the memory is called the input stream, and the output stream that writes the data from the memory into the external memory is called the output stream@ H_ 403_ 2@

Flow is a very vivid concept when @ h_ 403_ 2 @ program @ h_ 403_ 2@@H_ 403_ 2@ when you need to read data, you will open a stream to the data source, which can be file, memory or network connection. Similarly, when the program needs to write data, it will open a stream to the destination@ H_ 403_ 2@@H_ 403_ 2@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>