DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links