Why is BufferedReader read() much slower than readLine()?

后端 未结 6 798
不思量自难忘°
不思量自难忘° 2020-12-29 18:45

I need to read a file one character at a time and I\'m using the read() method from BufferedReader. *

I found that read() is a

6条回答
  •  梦谈多话
    2020-12-29 19:24

    According to the documentation:

    Every read() method call makes an expensive system call.

    Every readLine() method call still makes an expensive system call, however, for more bytes at once, so there are fewer calls.

    Similar situation happens when we make database update command for each record we want to update, versus a batch update, where we make one call for all the records.

提交回复
热议问题