Quero simular o comando cat do linux.
Daí preciso saber se o cara clicou na tecla “Enter” na linha de comando.
Obrigado.
Abraços.
Quero simular o comando cat do linux.
Daí preciso saber se o cara clicou na tecla “Enter” na linha de comando.
Obrigado.
Abraços.
O programa cat não é interativo, não vejo por quê você tenha que capturar tecla alguma do usuário; a menos que na realidade você esteja desenvolvendo seja um prompt/interpretador de comandos.
Pois é. O meu precisa ser interativo.
Ninguém?
Reading a string the user enters at a command-line prompt
The basic technique of reading a String provided by a user at a command-line is fairly simple, but more lengthy than you’d expect. It involves the use of the System.in object, along with the InputStreamReader and BufferedReader classes. The code in Listing 1 shows how you can prompt the user to enter a String value, such as their name, and then read that value.
import java.io.*;
public class ReadString {
public static void main (String[] args) {
// prompt the user to enter their name
System.out.print("Enter your name: ");
// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String userName = null;
// read the username from the command-line; need to use try/catch with the
// readLine() method
try {
userName = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read your name!");
System.exit(1);
}
System.out.println("Thanks for the name, " + userName);
}
} // end of ReadString class