Input from user in console application
Hey all,
I've been reading through my java book(s) and have yet to see a simple way
to get user input from the keyboard for a console application.
I'm just starting out with java but have a good amount of experience with
C/C++ and am used to having a basic io method e.g. cin >> , readln etc...
What gives??
Thanks for any help/info in advance!
Gerry
Re: Input from user in console application
"Gerry" <gerry.webguru@gte.net> wrote:
>
>Hey all,
>I've been reading through my java book(s) and have yet to see a simple way
>to get user input from the keyboard for a console application.
>
>I'm just starting out with java but have a good amount of experience with
>C/C++ and am used to having a basic io method e.g. cin >> , readln etc...
>
>What gives??
>
>Thanks for any help/info in advance!
>
>Gerry
Yeah, good question. There's very little coverage of this topic as everyone
is enamored with Swing as a user-interface. I've got three responses for
you:
1. You can read a character with the simple line:
char a = System.in.read();
2. You can read a string by wrapping the System.in input stream with a BufferedReader:
BufferedReader in = new BufferedReader(
new InputStreamReader( System.in ) );
String input = in.readLine();
3. Wait for this month's 10-minute solution. The topic is "Creating an interactive
command line interface". It goes into greater depth and gives tips on how
to design a reusable framework for this.
Happy Coding!
Cordially,
Kyle Gabhart
DevX Java Pro