import java.io.*; public class ReadFile { public static void main(String args[]) { try { FileReader fr = new FileReader("input.txt"); BufferedReader br = new BufferedReader(fr); if (br.ready()) { String line = br.readLine(); System.out.println(line); } br.close(); } catch(Exception e) { e.printStackTrace(); } } }
import java.io.*; public class ReadStdIn { public static void main(String args[]) { try { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); if (br.ready()) { String line = br.readLine(); System.out.println(line); } br.close(); } catch(Exception e) { e.printStackTrace(); } } }The BufferedReader class is part of the java.io package library.