public static void main (String[] args) {
try{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println ("1..case1 | 2..case2");
String ch=Integer.parseInt(bf.readLine()); //user input for switch
System.out.println (ch);
bf.close();
switch(ch) { //userinput ch variable switch in case
case 1 :
String data=bf.readLine();
bf.close();
System.out.println(data);
break;
case 2 :
System.out.print ("Enter Key ");
String key=bf.readLine();
bf.close();
System.out.println(key);
break;
default :
System.out.println ("wrong choice");
}
}
catch(IOException e){
System.out.println ("io error");
}
bf.close();
}
//每次在第一次用戶輸入後,它進入部分匹配的情況下,但在下一個用戶輸入引發異常。在java中的BufferedReader,總是拋出異常
請幫助.. 在此先感謝..
請告訴我例外呢? –
你想讀一個行郵堆棧跟蹤_after_讀者被關閉。不能這樣做。 –
所以當我應該使用.close()函數.. – sanjitguin