Search
Sponsors
Sponsors

Keyboard input

 

import java.io.*;

public class ReadString {

   public static void main (String[] args) {

      //  prompt the user to enter their name
      System.out.print("Enter your name: ");

      //  open up standard input
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      String userName = null;

      //  read the username from the command-line; need to use try/catch with the
      //  readLine() method
      try {
         userName = br.readLine();
      } catch (IOException ioe) {
         System.out.println("IO error trying to read your name!");
         System.exit(1);
      }

      System.out.println("Thanks for the name, " + userName);

   }

}  // end of ReadString class

Related posts:

  1. Send SMS using SMSMatrix   try { String MATRIXURL = "http://www.smsmatrix.com/matrix"; String PHONE =...
  2. Read a file   import java.net.*; import java.io.*; public class URLReader {    ...
  3. Download a forex quote   import java.net.*; import java.io.*; public class ForexTest {    ...
  4. Read a file   File multiUserFile = new File("test.txt"); String line = "";...
  5. File read and write example   import java.util.Vector; import java.io.*; public class FileUtility {    ...

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

Translate