Java Console readline() MethodThe readline() Method of Console class is used to read a single line of text from the console. SyntaxParametersNA 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 1Output: Enter lines of text. Enter 'stop' to quit. Example 2Output: 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) MethodThe 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. SyntaxParametersfmt: 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 1Output: Enter your name: Jony Here is your name: Jony Example 2Output: Enter : javatpoint Alphabets entered: javatpoint
Next TopicJava Console Class
|