src/share/classes/java/io/Console.java

Print this page




  58  * <p>
  59  * Invoking <tt>close()</tt> on the objects returned by the {@link #reader()}
  60  * and the {@link #writer()} will not close the underlying stream of those
  61  * objects.
  62  * <p>
  63  * The console-read methods return <tt>null</tt> when the end of the
  64  * console input stream is reached, for example by typing control-D on
  65  * Unix or control-Z on Windows.  Subsequent read operations will succeed
  66  * if additional characters are later entered on the console's input
  67  * device.
  68  * <p>
  69  * Unless otherwise specified, passing a <tt>null</tt> argument to any method
  70  * in this class will cause a {@link NullPointerException} to be thrown.
  71  * <p>
  72  * <b>Security note:</b>
  73  * If an application needs to read a password or other secure data, it should
  74  * use {@link #readPassword()} or {@link #readPassword(String, Object...)} and
  75  * manually zero the returned character array after processing to minimize the
  76  * lifetime of sensitive data in memory.
  77  *
  78  * <blockquote><pre>
  79  * Console cons;
  80  * char[] passwd;
  81  * if ((cons = System.console()) != null &&
  82  *     (passwd = cons.readPassword("[%s]", "Password:")) != null) {
  83  *     ...
  84  *     java.util.Arrays.fill(passwd, ' ');
  85  * }
  86  * </pre></blockquote>
  87  *
  88  * @author  Xueming Shen
  89  * @since   1.6
  90  */
  91 
  92 public final class Console implements Flushable
  93 {
  94    /**
  95     * Retrieves the unique {@link java.io.PrintWriter PrintWriter} object
  96     * associated with this console.
  97     *
  98     * @return  The printwriter associated with this console
  99     */
 100     public PrintWriter writer() {
 101         return pw;
 102     }
 103 
 104    /**
 105     * Retrieves the unique {@link java.io.Reader Reader} object associated
 106     * with this console.




  58  * <p>
  59  * Invoking <tt>close()</tt> on the objects returned by the {@link #reader()}
  60  * and the {@link #writer()} will not close the underlying stream of those
  61  * objects.
  62  * <p>
  63  * The console-read methods return <tt>null</tt> when the end of the
  64  * console input stream is reached, for example by typing control-D on
  65  * Unix or control-Z on Windows.  Subsequent read operations will succeed
  66  * if additional characters are later entered on the console's input
  67  * device.
  68  * <p>
  69  * Unless otherwise specified, passing a <tt>null</tt> argument to any method
  70  * in this class will cause a {@link NullPointerException} to be thrown.
  71  * <p>
  72  * <b>Security note:</b>
  73  * If an application needs to read a password or other secure data, it should
  74  * use {@link #readPassword()} or {@link #readPassword(String, Object...)} and
  75  * manually zero the returned character array after processing to minimize the
  76  * lifetime of sensitive data in memory.
  77  *
  78  * <blockquote><pre>{@code
  79  * Console cons;
  80  * char[] passwd;
  81  * if ((cons = System.console()) != null &&
  82  *     (passwd = cons.readPassword("[%s]", "Password:")) != null) {
  83  *     ...
  84  *     java.util.Arrays.fill(passwd, ' ');
  85  * }
  86  * }</pre></blockquote>
  87  *
  88  * @author  Xueming Shen
  89  * @since   1.6
  90  */
  91 
  92 public final class Console implements Flushable
  93 {
  94    /**
  95     * Retrieves the unique {@link java.io.PrintWriter PrintWriter} object
  96     * associated with this console.
  97     *
  98     * @return  The printwriter associated with this console
  99     */
 100     public PrintWriter writer() {
 101         return pw;
 102     }
 103 
 104    /**
 105     * Retrieves the unique {@link java.io.Reader Reader} object associated
 106     * with this console.