• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading from STDIN  RSS feed

 
Greg Neef
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone be so kind as to point me in the write direction for reading in from the keyboard. I want to have my program loop and display a prompt then wait for user input and process what they key in.
SCJP 1.4
 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.in is basically an InputStream that is always open. So you can use it as such. Here is the JavaDoc for InputStream
InputStream JavaDoc
It is a bit unwieldy so watch your carriage returns! If you don't mind a little GUI in your program, you can use a JOptionPane.showInputDialog which will return a String from an input box.
Hope this helps.
 
Herb Schildt
Author
Ranch Hand
Posts: 253
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg:
Here is a skeletal application that shows one (of many) ways to read user input from the keyboard. Maybe it will help you get started. This one uses a buffered reader.

A sample run is shown here.
Enter strings. Use 'stop' to quit.
: one
You entered: one
: two
You entered: two
: three
You entered: three
: stop
You entered: stop
[ October 14, 2003: Message edited by: Herb Schildt ]
 
Greg Neef
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!