Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I get capture data from the keyboard????

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
hi.

I'm new to java, and would just like to know how to accept data from the keyboard (command prompt).
I realise that to print a line in the command prompt you use: "println()".
I have heard that you use the "read()" or something like that....

Hope anyone can help! all comments and suggestions welcome!
thanks every1.

JoE we are all of us living in the gutter.
But some of us are looking at the stars.
 
You can use System.in.read() to get an input from the keyboard.
 
I don't know of any simple way to get data from the keyboard, but this is what I always do:

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(isr);

Without gettting too technical, the first line converts a byte stream into a character stream and the second line creates a BufferedReader object that has a method called readLine that you are going to want to use. To capture input from the keyboard use:

String myMessage = stdin.readLine();

myMessage now holds all the info that came in from the keyboard until the user presses the return key.

Hope this helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top