当前位置: 代码迷 >> J2EE >> Steam closed错误
  详细解决方案

Steam closed错误

热度:486   发布时间:2016-04-22 03:23:12.0
Steam closed异常,求助
控制台程序的一段:
Java code
 public  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));       public int showHandle() throws IOException      {          showWelcome();          System.out.println("                 **********请输入您要的操作**********\n");          System.out.println("                     1  存款");          System.out.println("                    2  取款");          System.out.println("                    3  显示余额");          System.out.println("                    4  修改密码");          System.out.println("                    5  退出\n");          for (count = 0; count < 3; count++)          {              System.out.print("                请输入操作:");              try { choose = Integer.parseInt(br.readLine());}catch(IOException ioe){ioe.printStackTrace();}              if (choose != 1 && choose != 2 && choose != 3 && choose != 4 && choose != 5)              {                  showWelcome();                  System.out.println("\n\n                 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");                  System.out.println("                 XXX     您的输入有误!     XXX");                  System.out.println("                 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");              }              else              {                  return choose;              }          }          br.close();          return 0;      }


以上程序,前面显示部分没问题,在输入 1 后,按enter键,程序就进入了以下死循环:

  **********请输入您要的操作**********
  1 存款
  2 取款
  3 显示余额
  4 修改密码
  5 退出
   
  请输入操作:java.io.IOException:Stream closed 
  .........

以上打“”部分不停地显示。提示出错地方在这行try { choose = Integer.parseInt(br.readLine());}catch(IOException ioe){ioe.printStackTrace();}

真搞不懂哪里出了问题??请教!!


------解决方案--------------------
补完你的程序之后,运行没有问题。请检查你程序其它部分的逻辑。

Java code
import java.io.*;public class Test {    public  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        protected void showWelcome() {        System.out.println(" Welcome my testing ");    }        protected int choose;    public int showHandle() throws IOException {        showWelcome();        System.out.println("                 **********请输入您要的操作**********\n");        System.out.println("                     1  存款");        System.out.println("                    2  取款");        System.out.println("                    3  显示余额");        System.out.println("                    4  修改密码");        System.out.println("                    5  退出\n");        for (int count = 0; count < 3; count++) {            System.out.print("                请输入操作:");            try {                choose = Integer.parseInt(br.readLine());            } catch (IOException ioe) {                ioe.printStackTrace();            }            if (choose != 1 && choose != 2 && choose != 3 && choose != 4 && choose != 5) {                showWelcome();                System.out.println("\n\n                 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");                System.out.println("                 XXX     您的输入有误!     XXX");                System.out.println("                 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n");            } else {                return choose;            }        }        br.close();        return 0;    }        public static void main(String[] args) throws Exception {        Test test = new Test();        test.showHandle();    }}
  相关解决方案