¿Por qué querría usar java.io.Console sobre transmisiones estándar?

I realize this may be a duplicate question, such as, ¿Por qué utilizar java.io.Console?. However, I wanted a more detailed answer (pros/cons, applications, anything more).

Forgive me if I am misunderstanding this. So I ran a program using eclipse and I received the error message "No Console", so I just let it go and ran it via Terminal instead. However, I am a little unclear why is the console object doing this (I think it's because it returns null, but I wanted a more detailed answer). From various reads, it seems various IDEs such as Netbeans and Eclipse haven't "implemented" this properly. So it leads me to the question, and since this is my very first time seeing java.io.Console, why would I want to use this over standard streams? Examples for applications using console is appreciated and preferred!

preguntado el 09 de marzo de 12 a las 23:03

1 Respuestas

Programs written with interactive shells in mind provide a lot of conveniences to command line users

  • finalización de pestaña
  • history tracking
  • password input secure against shoulder surfers
  • colored and formatted output
  • using the preferred pager for paging text

Console allows java programs that are often invoked via the command line to present a good user-experience to users who invoke it in an interactive shell.

Por ejemplo, Console.readLine might sound like something very similar to BufferedReader.readLine, but when the program is run from an interactive bash shell, it behaves like UNIX readline

DESCRIPCIÓN

readline will read a line from the terminal and return it, using prompt as a prompt. If prompt is NULL or the empty string, no prompt is issued. The line returned is allocated with malloc(3); the caller must free it when finished. The line returned has the final newline removed, so only the text of the line remains.

readline offers editing capabilities while the user is entering the line. By default, the line editing commands are similar to those of emacs. A vi-style line editing interface is also available.

...

LA BÚSQUEDA

Readline provides commands for searching through the command history for lines containing a specified string. There are two search modes: incremental and non-incremental.


why would I want to use this over standard streams?

If your program produces textual output and its users are likely to include sysadmins who will often invoke it inside an interactive shell, they might benefit from Console.

Respondido el 20 de junio de 20 a las 10:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.