다음을 통해 공유


Console Class

Definition

Methods to access the character-based console device, if any, associated with the current Java virtual machine.

[Android.Runtime.Register("java/io/Console", DoNotGenerateAcw=true)]
public sealed class Console : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.IFlushable
[<Android.Runtime.Register("java/io/Console", DoNotGenerateAcw=true)>]
type Console = class
    inherit Object
    interface IFlushable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
Console
Attributes
Implements

Remarks

Methods to access the character-based console device, if any, associated with the current Java virtual machine.

Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.

If this virtual machine has a console then it is represented by a unique instance of this class which can be obtained by invoking the java.lang.System#console() method. If no console device is available then an invocation of that method will return null.

Read and write operations are synchronized to guarantee the atomic completion of critical operations; therefore invoking methods #readLine(), #readPassword(), #format format(), #printf printf() as well as the read, format and write operations on the objects returned by #reader() and #writer() may block in multithreaded scenarios.

Invoking close() on the objects returned by the #reader() and the #writer() will not close the underlying stream of those objects.

The console-read methods return null when the end of the console input stream is reached, for example by typing control-D on Unix or control-Z on Windows. Subsequent read operations will succeed if additional characters are later entered on the console's input device.

Unless otherwise specified, passing a null argument to any method in this class will cause a NullPointerException to be thrown.

<b>Security note:</b> If an application needs to read a password or other secure data, it should use #readPassword() or #readPassword(String, Object...) and manually zero the returned character array after processing to minimize the lifetime of sensitive data in memory.

<blockquote>

{@code
            Console cons;
            char[] passwd;
            if ((cons = System.console()) != null &&
                (passwd = cons.readPassword("[%s]", "Password:")) != null) {
                ...
                java.util.Arrays.fill(passwd, ' ');
            }
            }

</blockquote>

Added in 1.6.

Java documentation for java.io.Console.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
Flush()

Flushes the console and forces any buffered output to be written immediately .

Format(String, Object[])

Writes a formatted string to this console's output stream using the specified format string and arguments.

FormatAsync(String, Object[])
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Printf(String, Object[])

A convenience method to write a formatted string to this console's output stream using the specified format string and arguments.

PrintfAsync(String, Object[])
Reader()

Retrieves the unique java.io.Reader Reader object associated with this console.

ReadLine()

Reads a single line of text from the console.

ReadLine(String, Object[])

Reads a single line of text from the console.

ReadLineAsync()
ReadLineAsync(String, Object[])
ReadPassword()

Reads a password or passphrase from the console with echoing disabled

ReadPassword(String, Object[])

Reads a password or passphrase from the console with echoing disabled

ReadPasswordAsync()
ReadPasswordAsync(String, Object[])
SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Writer()

Retrieves the unique java.io.PrintWriter PrintWriter object associated with this console.

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
FlushAsync(IFlushable)

Applies to