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 difference between java stream and IO stream

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article introduces the knowledge of "what is the difference between java flow and IO stream". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Stream (Stream):

A stream represents any source that has the ability to produce data or a source object that can also receive data, and its purpose is to establish a transmission channel between the data source and the destination.

The most important thing in the stream is the IO stream. Let's talk about IO flow first.

IO stream is divided into input stream and output stream according to the direction, which is easy to understand. Input stream is called input stream, whereas output stream is called output stream.

According to the form: divided into character stream, and byte stream. This is not difficult, byte stream is basically can not be expressed in characters, pictures, video, audio, etc., and character streams, generally can be expressed in characters, txt,xlsx,java,html and so on.

According to the different functions, it can be divided into: node flow, processing flow. The node flow is the direct manipulation of the file, and the processing flow is the connection to the existing stream.

The following figure shows the four streams of the IO flow:

The four streams are all abstract classes, so you can't create objects directly. You need to new one of his implementation classes. The content of this article is generally conceptual. If you need specific code, you can leave a message for me. Below, I will put some primary interview questions about IO stream that I often ask (advanced follow-up I will write)

1. Streams are divided into two types according to their implementation functions, and examples are given respectively:

Answer: node flow, processing flow

Node flow: OutputStream

Processing flow: OutputStreamWriter

What kind of stream does 2.BufferedReader belong to? what is it mainly used for? there are some classic methods in it.

Answer: belongs to the buffer flow in the processing flow, you can store the read content in memory, there is a readLine () method.

3. If I want to read a lot of byte streams from the hard disk, I want to use that stream, why?

A: BufferedInputStream uses buffered streams to reduce damage to the hard disk.

4. If I want to print out different types of data to the data source, then the most appropriate stream is that stream. Why?

A: Printwriter can print various data types.

5. Which two streams are used to write an object to a data source or to read it from a data source?

Answer: ObjectInputStream ObjectOutputStream.

6. Does the stream generally need to be closed? if so, what method is used to close it? it is better to close it in that code block, how to close the processing flow, and how to close if multiple streams call each other.

A: once the flow is opened, it must be closed. Use the close method and put in the finally statement block (the finally statement must be executed). The called processing flow closes the processing flow, and multiple streams call each other to close only the outermost flow.

All the streams in 7.Java can be divided into several categories. What are their names and what do they stand for?

Answer: byte input stream InputStream

Byte output stream OutputStream

Character input stream Reader

Character output stream Writer

8. What is used to dynamically write the object to disk, and what interface is to be implemented?

Answer: ObjectInputStream, you need to implement the Serializable interface.

That's all for "what's the difference between java streams and IO streams". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Internet Technology

Wechat

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

12
Report