Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of Java flow

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the concept of Java flow". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the concept of Java flow".

First, Java flow definition.

Stream in Java is a very abstract concept. When a program needs to read a file, it opens a stream to the data source (the file being read). Stream is the abstraction of input and output devices. In Java programs, the input / output operations of data are carried out in a "stream" way. Devices can be files, networks, memory, etc.

II. Classification of streams in Java

1. Byte stream (Byte Stream)

InputStream (abstract class) and OutputStream (abstract class) the top-level parent of all byte streams, which are processed in Byte

2. Character stream (Character Stream)

Reader (Abstract Class) and Writer (Abstract Class) the top-level parent of all character streams, which are the basic units of characters represented by 16-bit Unicode.

Standard input / output streams

1. Standard output stream system.out

Output data to a standard output device with a data type of PrintStream

Common methods: void print (parameter) and void println (parameter)

System.out outputs parameters and line breaks by calling the println method, and does not wrap by calling the print method.

2. Standard input stream system.in

Input data to a standard input device (usually a keyboard) with a data type of InputStream

Common method: int read () returns ASCII code. If the return value is-1, no bytes are read. The reading work ends.

Int read (byte b []): reads multiple bytes into buffer b, and the return value is the number of bytes read

Package cn.itcase.stream

Import java.io.IOException

Public class Demo {

/ / enter what is typed from the keyboard and print what

Public static void main (String [] args) {

Int b

Try {

System.out.println ("please Input")

While ((b=System.in.read ())! =-1) {

System.out.println ((char) b)

}

} catch (IOException e) {

System.out.println (e.toString ())

}

}

}

3. Standard error stream

System.err standard error stream, whose data type is PrintStream.

IV. Icano streams are classified by type.

1 、 Memory

Read and write data from / to memory array: CharArrayReader,CharArrayWriter,ByteArrayInputStream,ByteArrayOutputStream

Read and write data from / to memory string: StringReader,StringWriter,StringBufferInputStream,StringBufferOutStream

2. Pipe pipeline

Implement the input and output of pipes (interprocess communication): PipedReader,PipeWriter,PipedInputStream,PipedOutputStream

3. File file stream

Read and write to the file: FileReader,FileWriter,FileInputStream,FileOutputStream

4 、 ObjectSerialization

Object input, output: ObjectInputStream,ObjectOutputStream

5. DataConversion data flow

Read and write according to the basic data type (the data processed is the basic data type of Java): DataInputStream,DateOutputStream

6 、 Printing

Contains a convenient printing method: PrintWriter,PrintStream

7. Buffering buffer

Data is cached during read-in and write-out to reduce the number of BufferedReader,BufferedWriter,BufferedIputStream,BuffereOutputStream O

8. Filtering filter flow

Filter when data is read and written: FilterReader,FilterWriter,FilerInputStream,FilterOutputStream

9 、 Concatenation

Merge inputs and connect multiple input streams into a single input stream: SequenceInputStream

10 、 Conunting

Count rows when reading data: LineNumberReader,LineNumberInputStream

11 、 Peeking Ahead

Pre-read through caching mechanism: PushBackReader,PushBackInputStream

12 、 Converting between Bytes and Characters

Convert a byte stream to a character stream according to a certain encoding / decoding standard, or reverse conversion (Stream to Reader,Writer conversion class): InputStreamReader,OutputStreamWriter

Thank you for your reading, the above is the content of "what is the concept of Java flow". After the study of this article, I believe you have a deeper understanding of what the concept of Java flow is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report