求助!關於執行緒的問題?各位大俠謝謝了!!!

彭飛2003發表於2003-10-31
我想透過執行緒控制螢幕輸入,但是我使用 InputStreamReader in = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(in); 的buf.readLine()方法,所以在呼叫該方法的方法中加丟擲例外,那麼我在使用執行緒時,重寫RUN()方法,但是也同樣對RUN()方法加丟擲例外,這樣做對嗎?程式碼如下:
public class Group extends Thread {
Vector v = new Vector();
public void run() throws IOException
{
InputStreamReader in = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(in);
do {
person tmp = new person();
v.addElement(tmp);
String AgeTemp;
System.out.print("Input name:");
tmp.setName(buf.readLine());

System.out.print("Input age:");
AgeTemp = buf.readLine();
tmp.setAge(Integer.parseInt(AgeTemp)) ;

System.out.print("Input sex:");
tmp.setSex(buf.readLine()) ;

System.out.print("Input univ:");
tmp.setUniv(buf.readLine()) ;
System.out.println("type 'q' to finish input.");

} while (!buf.readLine().equals("q"));
}


public static void main(String args[]) throws IOException{
Vector v=new Vector();
Group gp = new Group();
gp.start();
//gp.SortMothd();
//gp.StrPrint();
//gp.SortMothd(man);
}
}

相關文章