Alternative to the Scanner for data entry

8

In Java, when we are learning to capture data entry, usually by text mode, we are instructed to use the class Scanner .

Is there any alternative to Scanner to capture data entry by text mode? If so, how does it work?

    
asked by anonymous 21.02.2016 / 14:37

2 answers

8

According to this answer in the SOen :

Class BufferedReader and InputStreamReader

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int i = Integer.parseInt(br.readLine());

Class DataInputStream

DataInputStream dis = new DataInputStream(System.in);
int i = dis.readInt();

The readLine no DataInputStream is deprecated, to get the value of String you can use the previous solution with BufferedReader .

Class Console

Console console = System.console();
String s = console.readLine();
int i = Integer.parseInt(console.readLine());

It seems like this method does not work on some IDEs.

    
21.02.2016 / 14:47
6

I do not know if this would be a viable alternative, but you can use JOptionPane to get input data.

String nome = JOptionPane.showInputDialog("Entre com um nome: ");
    
21.02.2016 / 18:37