Java flow operation

xiaoxiao2021-03-06  46

Java flow operation

Java's flow campaign is divided into byte stream and character stream.

1, byte stream

All read operations inherit from a public superclass Java.io.InputStream class.

All write operations have inherited from a public super-class Java.io.OutputStream class.

InputStream and OutputStream are abstract classes.

InputStream has 6 low-level input streams:

Low-level flowing use BYTEARRAYINPUTSTREAM Reads Data byte FileInputStream from the memory array FileInputStream reads data bytes from the local file system PipedInputStream reads data bytes from the threading pipe StringBufferInputStream reads data bytes from the string SequenceInputStream from two Or read the data byte in multiple low streams, and read data bytes from one stream to another when arriving at the end of the stream.

InputStream is also a subclass: filter flow java.io.filterInputStream. Filter streams can be wrapped up and provide more convenient usage.

The FilterInputStream class constructs FilterInputStream (InputStream), create an input stream filter over the specified input stream.

The common subclasses of FilterInputStream are as follows:

The filter inputs the use of the BufferedInputStream buffer to access the data to improve the efficiency DataInputStream reads the basic data type from the input stream, such as int, float, double, or even a line of text LINENUMBERINPUTSTREAM on the basis of the translation line end of the translation line. Maintenance A counter that indicates which row is being read. PushbackInputStream allows the first part of the data byte to the stream

OutputStream (omitted)

The structure of OutputStream is basically the same as InputStream.

2, character stream

Note: It is introduced in JDK1.1, and the above word stream is introduced in JDK1.0. When used to process text data, select the character flow than the word throttle. But the byte stream can continue to be used for developers who only route basic data types.

All readings are inherited from a public super class Java.io.Reader class.

All write operations have inherited from a public super-class Java.io.writer class.

The same Reader and Writer are also an abstract class.

The common subclasses of Reader are as follows:

Low-level reader flow Use ChararrayReader reads Data InputStreamReader FileReader (subcategory of InputStreamReader) from the character array, read characters from the local file system StringReader reads a character sequence from the string to read characters from the thread pipeline

InputStreamReader focus on:

InputStreamReader is read data from the input stream and the connection input is flowd from the reader. Such as:

New INPUTSTREAMREADER (System.in)

Construction method:

InputStreamReader (InputStream)

Create an InputStreamReader with default character encoding.

InputStreamReader (InputStream, String)

Create an InputStreamReader with named character encoding.

Common filter readers:

The use of the filter reader stream is access to the data of the bufferedReader buffer data to improve the efficiency LINENUMBERREADER (subclass of BufferedReader) to maintain a counter, which indicates which line is reading. FilterReader provides a class to create a filter that can extend this class PushbackReader (subclass of FilterReader) allows the text data to be pushed back to the reader. These filter readers can be introduced into a Reader as a configuration. Parameters of the method.

Writer (slightly)

The structure of the Writer is basically the same as Reader.

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

New Post(0)