Primary Java IO review (1)

zhaozj2021-02-16  47

Java IO review

Some people inside the forum ask about things about Java IO, the younger brother is not talented. Write something, I hope to give you some inspiration, it is also a throwing brick. ^ _ ^

Java's IO packets support Java's basic input / output (I / O) system, as well as input and output of files. Java's IO section, I intend to elaborate in two parts, first we discuss the foundation of the IO subsystem, and then discuss in-depth parts.

If you have a Java encoding experience, you will find that these programs are not used to use a lot of IO subsystems. In fact, in addition to print () and println (), there is basically no other IO method. The reason is very simple: Most actual Java applications are not based on text, consisters, but based on graphical AppLiaction, which relies on the Java AWT and Swing classes of the user's interaction. At the same time, Java supports the support of the console IO program is not very good, even in a simple example, but based on the text, the Java program in the console also needs us to know.

Java IO is implemented via stream. About streaming, you can understand that it is a "data pipeline". Things that flow in the pipe can be based on bytes, or may be based on characters. It is as if it can flow in the pipe, or it can flow oil. There is also a concept corresponding to stream: input, output device. These devices can be disk files, keyboards (input devices), display (output devices), printers (output devices), network sockets, and more.

Below, let's understand "stream".

Two types of streams are defined in Java: byte, and characters.

Byte stream: Processing the input and output of bytes. Includes contents of reading and writing binary data.

Character stream: Handling the input and output of characters. He uses Unicode encoding and can achieve internationalization. Another advantage of using a character stream is that the character flow is more efficient than by the word.

:::::::::: byte flow :::::: :::::::::::::::::::

The byte stream contains two top abstractions: InputStream and OutputStream. As shown below.

Figure 1: InputStream Abstract Class Figure 2: Outpurstream Abstract Class

From the above two graphics (graphic from J2SE 1.4.2 DOC), we can see a few: 1: The two top layers of byte stream are abstract classes, namely InputStream and OutputStream. 2: Each abstract class has a subclass to achieve a specific function, processing the input and output of different devices. Next, a simple introduction of words, several common subsystems :::

Byte stream function brief introduction DataInputStream contains input streams that read Java standard data types DataOutputStream contains the output stream of the Java standard data type. ByTearRayInputStream writes the input stream of the byte array ByteArrayoutputStream writes the output stream of the byte array FileInputStream The output stream of the input stream FileOutputStream written in the file PrintStream contains the most common output () and printstream output stream PushbackInputStream Returns a byte to the input stream, which is mainly used for the compiler's implementation PiPutStream Output Pipe PipedputStream input the conduit SequenceInputStream n input streams together, one by one read RandomAccessFile random access file in a certain order BufferInputStream buffered input stream BufferOutputStream buffered output stream FilterInputStream achieved InputStream Interface FilterOutputStream achieved OutputStream Interface InputStream abstract class OutputStream abstract description of the input stream Class, description stream input Abstract class InputStream and Outpurstream define a practical method, the most important is read () and Write (). These two methods are declared as abstract methods in InputStream and OutputStream, and are implemented by sub-stream OverWrite.

转载请注明原文地址:https://www.9cbs.com/read-23390.html

New Post(0)