Reading Console using BufferedReader Java

In this tutorial, I am going to share simple program about Reading Console using BufferedReader Java. The example program has been tested and output shared in the same post.

BufferedReaderExample.java

package com.dineshkrish.files;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BufferedReaderExample {
public static void main(String[] args) throws IOException {
// Defining the BufferedReader Object to read console data
BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the value :");
try {
// Invoking the readLine() method to read data
String data = consoleReader.readLine();
System.out.println("Read from Console : "+data);
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
consoleReader.close();
}
}
}

Output

—————-
Enter the value :Hello world
Read from Console : Hello world

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *