2013-02-15 59 views
1

在Java中獲取輸入的不同方式有哪些?在Java中獲取輸入的不同方法

我用兩種方法:

BufferedReader

Scanner

是否有任何其他方式獲得的輸入?

如果有,他們之間有什麼區別?

+3

如果在Google上工作,請在Google上輸入相同的名稱。 – 2013-02-15 16:24:14

+1

還有幾種類型的閱讀器,隨時閱讀並提出具體問題。 http://docs.oracle.com/javase/6/docs/api/java/io/Reader.html – 2013-02-15 16:24:37

+0

@AchintyaJha先生,我希望這裏的大部分問題,首先通過Google找到他們的方式,並在需要時來到這裏更多解釋。 – Swamy 2013-02-15 16:39:45

回答

3

以及我嘗試了一些方法來看看如何通過不同的對象輸入的可能性和我探討它在4種不同的方式

 public String input1() 
{ 
    System.out.println("enter the input"); 
    Scanner sc=new Scanner(System.in); 
    String s1=sc.nextLine(); 
    return s1; 
} 
public String input2()throws IOError 
{ 

    Console c=System.console(); 
    String s2=null; 
    s2=c.readLine("enter the value"); 
    return s2; 
} 
public String input3() 
{ 
    System.out.println("enter the input"); 
    String s3=javax.swing.JOptionPane.showInputDialog("enter the text"); 
    return s3; 

} 
public String input4()throws Exception 
{ 
    System.out.println("enter the input"); 
    InputStreamReader isr=new InputStreamReader(System.in); 
    BufferedReader br=new BufferedReader(isr); 
    String s4=br.readLine(); 
    return s4; 
} 

如果我再遇到,我一定會列在這裏