Android: BufferedOutputStream needed when saving file to internal data?

I wanted to save the line in a file and read it, so I followed the following two examples:

However, both of them do not use the BufferedOutputStream wrapper, but the FileOutputStream document recommends.

Was this done to have a simpler example, or is it really not needed on Android? And does any answer also apply to an InputStream?

Regards, Jellyfish

+4
source share
1 answer

In this case, the authors of the examples know that the size of the output is small ahead of schedule. You really only need a buffered version if you have β€œlarge” amounts of data to write (which you usually don't know for absolute certainty ahead of time).

JavaDocs for BufferedOutputStream emphasizes this ...

Expensive interactions with the main input stream are minimized, since most (smaller) requests can be satisfied by accessing the buffer alone.

+3
source

Source: https://habr.com/ru/post/1346569/


All Articles