package BookDemo; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class FileStudentUtil { /** * 使用io流,獲取從鍵盤輸入到程序。使用Input(從外部設備到程序為輸入,程序到外部設備而為輸出); * System.in(out)標準系統(tǒng)輸入輸出中,不需要關閉流。否則在后面測試類中會回報流關閉錯誤 */ public static String getStringKeyBoard(){ String name=""; InputStreamReader isr = null; BufferedReader br = null; try { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); name = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return name; } public static Float getfloatKeyBoard() { // TODO Auto-generated method stub Float price=(float) 0; InputStreamReader isr = null; BufferedReader br = null; try { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); price = Float.parseFloat(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return price; } public static int getintKeyBoard(){ while(true){ int number=0; InputStreamReader isr= null; BufferedReader br = null; try { isr= new InputStreamReader(System.in); br = new BufferedReader(isr); String s=br.readLine();//在緩沖流中用readLine(),每行讀成String型。在轉換成int型 number=Integer.parseInt(s); return number; } catch (IOException e) { e.printStackTrace(); }catch(NumberFormatException a){ System.out.println("請輸入正確數(shù)值格式"); } } //return 0; } }
|
|
來自: weixiaofeng01 > 《Bookdemo》