“This is the fifth day of my participation in the August More Text Challenge. For details, see: August More Text Challenge.”

The vast sea of thousands of thousands, thank you for this second you see here. Hope my article is helpful to you!

Wish you in the future, keep love, go to the mountains and seas!

First look IO streams

After our study of “File” class yesterday, we know that “File” can be used to represent the information of files and directories, and we have gradually become proficient in basic File operations.

However, File does not represent the contents of the File, and after today’s general understanding of I/O streams, subsequent I/O stream operations can be used to read and write files.

Now that we finally get to our main topic, what is an IO stream? Why do I need an IO stream? What are the categories of IO streams?

Today? First focus on the type of I/O stream for a classification, I/O stream for a concept classification process.

What is an IO stream

In real life, you might need to use a USB flash drive to transfer files. In that case, data transmission can be regarded as a flow of data. According to the flow direction and based on memory, it can be divided into input input and output output, that is, the flow to memory is the input stream and the output stream out of memory.

Java operates on data through streams. IO streams are used to transfer data between devices, upload files and download files. The objects Java uses to operate on streams are in IO packages.

Classification of I/O streams

You can see:

  • According to the different data flow direction, it can be divided into input stream and output stream
  • According to the different types of data processing can be divided into: character stream and byte stream
  • The top-level superclass
The input stream The output stream
Byte stream Byte input streamInputStream Byte output streamOutputStream
Characters of the flow Character input streamReader Character output streamWriter

Specific I/O flow classification diagram:

Of course, this is just a list of the common classes, if you want to see more classes, you can check out the official JDK documentation API.

The concept of byte stream, input output stream

1. Character stream and byte stream

The origin of character streams: because of the differences in data encoding, there are stream objects that can operate on characters efficiently. Essentially, when reading a byte stream, it looks up the specified code table. The difference between a byte stream and a character stream

  • The units of read and write are different: byte stream is in bytes (8 bits), and character stream is in characters. The characters are mapped according to the code table. Multiple bytes may be read at a time.
  • Processing objects are different: byte streams can handle all types of data (such as pictures, AVI, etc.), while character streams can only handle character types of data.
  • Conclusion: Whenever you’re dealing with plain text data, character streams are preferred. Everything else uses byte streams.

2. Input and output streams

The input stream can only be read, and the output stream can only be written. The program needs to use different streams according to the characteristics of the data to be transmitted.

conclusion

I believe that you are looking at the IO stream at the beginning of the IO stream classification has a certain understanding, looking forward to waiting for the next PART of the IO stream byte stream teaching!

Of course, there are many streams waiting to watch together next time! Welcome to the next chapter!

So far, the world is closed for today, good night! Although this article is over, BUT I still, never finished. I will try to keep writing articles. The coming days are long, and the horse is slow!

Thank you for seeing this! May you be young and have no regrets!

Note: If there are any mistakes and suggestions, please leave a message! If this article is also helpful to you, I hope you give a lovely and kind attention, thank you very much!