android - java中字节流读写和字符流读写怎么理解?哪个效率更高
高洛峰
高洛峰 2017-04-17 16:43:03
0
3
809
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
阿神

All IO operations are completed through bytes. There is no concept of characters at the bottom of the system. In Java, there are only byte operation methods and no string methods in InputStream and OutputStream. All stream encapsulated objects that can read and write strings are implemented in the upper layer and are convenient to use.

The specific choice of which stream to use and the efficiency between them all depend on the specific scenario and the purpose of the function. There is no simple good or bad.

With your two examples above, the effect is exactly the same, except that you choose to use the internal implementation of BufferedWriter and BufferedReader or the byte implementation of Buffer buffering.

Java is open source. It is recommended to read more source code and become familiar with the internal principles and implementation.

Peter_Zhu

The difference between the two is that the byte stream can operate both text files and non-text files, such as some binary data (pictures, videos, objects), while the character stream can only operate text. This is also the applicable situation for both. How to decide which data stream to use for reading and writing depends on the type of data to be read and written. If it is a text file, of course, choose the character stream, because we all know that the character stream processes 2 units at a time. Bytes of Unicode characters, and the byte stream processes one at a time. If it is a non-text file, then you can only use the byte stream. At this time, you cannot simply look at who is more efficient. I think this is why there are two data streams.

迷茫

There is almost no difference in reading and writing small files.
For reading and writing large files, Buffer is better. For multiple reads and writes to the hard disk, a good caching mechanism can be faster. For example, for a 60GB file, you must read and write it in batches (or even in separate rows) multiple times.
Secondly, do you want to process characters or bytes? Choose according to your needs.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template