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.
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.
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.
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.