keyboard inputs


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: keyboard inputs

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Posts
    2

    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 10:13 PM.

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

    Code:
    //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:
    Code:
    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:
    Code:
    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, 11:35 PM
  2. Problem in simulate keyboard event
    By Dasensa Esente in forum VB Classic
    Replies: 2
    Last Post: 06-06-2002, 04:27 AM
  3. Keyboard Logging
    By James Abbott in forum VB Classic
    Replies: 2
    Last Post: 11-22-2001, 03:00 PM
  4. Keyboard Logging
    By James Abbott in forum VB Classic
    Replies: 0
    Last Post: 11-22-2001, 06:26 AM
  5. Swedish keyboard with Gnome
    By Mattias Segnestam in forum Open Source
    Replies: 0
    Last Post: 12-17-2000, 04: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
 
 
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