Javatpoint Logo
Javatpoint Logo

Java Console readline() Method

The readline() Method of Console class is used to read a single line of text from the console.

Syntax

Parameters

NA

Return value:

This method returns the string containing the line read from the console.

Exception:

IOException: This exception will throw if an I/O error occurs.

Example 1

Output:

Enter lines of text.
Enter 'stop' to quit.

Example 2

Output:

File Read:
The main difference between BufferedReader and BufferedInputStream is that BufferedReader reads characters (text), whereas the BufferedInputStream reads raw bytes.
Null

Java Console readLine(String fmt, Object args) Method

The readLine(String fmt, Object args) method is a static method of Java Console class. It is used to provide a formatted prompt, then reads a single line of text from the console.

Syntax

Parameters

fmt: A format string as described in Format string syntax.

args: Arguments referenced by the format specifiers in the format string, the extra arguments are ignored.

Return value:

This method returns the string which contains the line read from the console. It does not include any line-termination characters. If an end of the stream has been reached, this method will return null.

Exception:

IllegalFormatException: If given the format string is incompatible and insufficient arguments.

IOError: If an I/O error occurs.

Example 1

Output:

Enter your name: Jony
Here is your name: Jony

Example 2

Output:

Enter : javatpoint
Alphabets entered: javatpoint
Next TopicJava Console Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA