Summary of file reading and writing (input stream and output stream) operations in Android

1. The principle of file reading and writing in Android: (1) all files are stored in bytes. (2) What is retained on the disk is not the characters of the file, but first encode the characters into bytes, and then store these bytes to the disk. (3) . when reading a file (especially a text file), it is also read byte by byte to form a byte sequence.

2. Difference between byte stream and character stream:

(1) . byte stream provides the function of processing any type of IO operation, but it cannot directly process Unicode characters. Character stream can. (2) . byte stream can be converted into character stream with inputstreamreader and outputstreamwriter. We usually use byte stream when we use it.

3. Steps of document reading and writing:

(1) First, establish the channel. (2) . then establish data storage space. (3) Then start reading and writing data. (4) . close the flow.

4. Input and output streams:

(1) . input stream: the program reads the data source from the input stream. The data source includes the outside world (keyboard, file, network...), that is, the communication channel that reads the data source into the program.

(2) . output stream: the program writes data to the output stream. A communication channel that outputs the data in the program to the outside world (display, printer, file, network...).

The code is as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>