DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: keyboard inputs

  1. #1
    Join Date
    Sep 2005

    keyboard inputs

    i was reading up on this syntax and it said that this automatically stores everything as int and ot convert it to char you would need to do something like - ch = (char) System.in.read();. well i was wondering if there is a way to convert to and store a string. i am basically looking to store a string value (name) through user input.
    Last edited by someone; 09-21-2005 at 09:13 PM.

  2. #2
    Join Date
    Aug 2005
    A way to read a string from the user is shown below:

    //get buffered reader
    BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
    //get line
    String line = in.readLine();
    //get another line
    String line2 = in.readLine();
    .. etc. Remember to import java.io
    If a line consist of many words you can tokenize the line:
    StringTokenizer tok = new StringTokenizer(line);
    tok.nextToken(); //gets the first word
    tok.nextToken(); //gets the second word
    tok.nextToken(); //gets the third word
    The above code breaks up the line by using the 'space' as a delimiter. To use some other character (like a comma) as a delimited replace the first line above with:
    StringTokenizer tok = new StringTokenizer(line, ',');
    For more help, www.NeedProgrammingHelp.com

Similar Threads

  1. Keyboard event
    By Varrus in forum VB Classic
    Replies: 1
    Last Post: 03-16-2005, 10:35 PM
  2. Problem in simulate keyboard event
    By Dasensa Esente in forum VB Classic
    Replies: 2
    Last Post: 06-06-2002, 03:27 AM
  3. Keyboard Logging
    By James Abbott in forum VB Classic
    Replies: 2
    Last Post: 11-22-2001, 02:00 PM
  4. Keyboard Logging
    By James Abbott in forum VB Classic
    Replies: 0
    Last Post: 11-22-2001, 05:26 AM
  5. Swedish keyboard with Gnome
    By Mattias Segnestam in forum Open Source
    Replies: 0
    Last Post: 12-17-2000, 03:33 PM

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.