ConsoleReader.java

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;

/**

* @author wbshi

*一个方便的键盘输入程序,可以在其他程序中import

**/

 

public class ConsoleReader

{
 private BufferedReader reader;
 
  public ConsoleReader(InputStream inStream)
  {
    reader = new BufferedReader (new InputStreamReader(inStream));
  }

 
  public int readInt()
  {
    String inputString = readLine();
    int n = Integer.parseInt(inputString);

    return n;
   }
 
 
  public double readDouble()
  {
    String inputString = readLine();
    double x = Double.parseDouble(inputString);

    return x;
  }

  public String readLine()
  {
    String inputLine = "";

    try
    {
       inputLine = reader.readLine();
    }
    catch(IOException e)
    {
      System.out.println(e);
      System.exit(1);
    }

    return inputLine;
   }

 
  /*
  public  static void  main(String s[]){

   int i;
    System.out.println("Please input a integer :");
   ConsoleReader reader=new  ConsoleReader(System.in);
       i=reader.readInt() ;

   System.out.println(i);

   }
   */

 
}

阅读更多
想对作者说点什么? 我来说一句