DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: keyboard inputs

  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 09: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, 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

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