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?
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?
According to this answer in the SOen :
BufferedReader
and InputStreamReader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int i = Integer.parseInt(br.readLine());
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
.
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.
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: ");