954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

System.in.read() V.S readLine()

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.

slasherpunk
Newbie Poster
15 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 
potential memory wastage


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

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

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.

Rameshwar Soni
Newbie Poster
19 posts since Aug 2011
Reputation Points: 19
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: