Input from user in console application


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Input from user in console application

Hybrid View

  1. #1
    Gerry Guest

    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

  2. #2
    Kyle Gabhart Guest

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center