import java.io.*; public class ReadFile { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new FileReader("filename.txt")); String line = br.readLine(); while (line != null) { System.out.println(line); line = br.readLine(); } br.close(); } catch (IOException e) { System.out.println("Error reading file."); } } }
import java.io.*; public class ReadInput { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your name: "); String name = br.readLine(); System.out.println("Hello " + name); } catch (IOException e) { System.out.println("Error reading input."); } } }In this example, we use the BufferedReader class to read user input from the console. We use the readLine() method to read the input and store it in a String variable named "name". We then print a greeting message to the console, using the value entered by the user. Overall, the java.io.BufferedReader class is a powerful tool for managing text input streams in Java. It is a part of the standard Java library, making it available to all Java developers.