![]() |
Buffered input?
Do I need the following lines of code when I want to input whole lines of text? If so, why do I need them? I found this code on the internet but I'm unsure of the purpose behind it. I tried google searching for the answer but came up short.
:
InputStreamReader converter = new InputStreamReader(System.in); |
Re: Buffered input?
That is one way to read standard input. A better way is to use a Scanner:
:
Scanner sc = new Scanner(System.in); |
Re: Buffered input?
Also, remember to import the scanner class first.
:
import java.util.Scanner; |
Re: Buffered input?
Thanks guys. But what is the purpose of buffered input? Why is there a need to use those lines of code when you use the readLine() function?
|
Re: Buffered input?
It leads to more efficient programming apparently. It stores collected input output into temporary storage area. For example instead of reading each key stroke, it is collected into a buffer until the enter key is pressed.
When you use the buffer, it is using a class. You have to write code to declare it and use it, it is a bit weird at first to get used to JAVA and classes, but you get used to it. |
Re: Buffered input?
> Why is there a need to use those lines of code when you use the readLine() function?
Scanner class was introduced in JDK 1.5 as a utility class which would serve as a golden hammer when doing I/O. Prior to that, if you wanted to accept user input via console, you had to use the BufferedReader, the way it is specified in the second post. |
Re: Buffered input?
Build a piece of hardware and make it amenable to people who don't understand the bottom line. What else can I say?
|
| All times are GMT -5. The time now is 3:29 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC