bufferedreader methods code example

Example 1: bufferedreader java

import java.io.BufferedReader;
//
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println(reader.readLine());

Example 2: BufferredReader Class

package com.javatpoint;  
import java.io.*;  
public class BufferedReaderExample{    
public static void main(String args[])throws Exception{             
    InputStreamReader r=new InputStreamReader(System.in);    
    BufferedReader br=new BufferedReader(r);            
    System.out.println("Enter your name");    
    String name=br.readLine();    
    System.out.println("Welcome "+name);    
}    
}

Example 3: java bufferedreader

private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer st;
static String next() throws IOException {
    while (st==null||!st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine().trim());
    }
    return st.nextToken();
}
static long readLong() throws IOException {
    return Long.parseLong(next());
}
static int readInt() throws IOException {
    return Integer.parseInt(next());
}
static double readDouble() throws IOException {
    return Double.parseDouble(next());
}
static String readLine() throws IOException {
    return br.readLine().trim();
}

Tags:

Java Example