Isn't it better to use the BufferedReader function readLine() instead of read() or read(byte[])?

The reason I ask is because of potential memory wastage by the read() function.
If I specify a byte array of size 10, then it will become capable of accepting ten bytes from the transmitter. However, if the transmitter transmits only four bytes, the remaining six bytes would be wasted.

Keeping this in mind, it would be practically smarter to use the readLine() function to avoid any memory wastage.

I am an absolute beginner in Java, so please pardon me if I sound incompetent.

Recommended Answers

All 2 Replies

potential memory wastage

Forget about this idea for a long time. With Mega and Giga byte machines, 10K doesn't mean anything.

I think when we are taking an numeric value like an int, double from user as an input it is always better to go for the Scanner class instead of BufferedReader class because if we are using the latter one then we have to again parse it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.