java bufferedreader code example
Example 1: java read file bufferedreader
try {
File file = new File("data.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch(IOException e) {
e.printStackTrace();
}
Example 2: bufferedreader java
import java.io.BufferedReader;
//
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println(reader.readLine());
Example 3: bufferedreader in java
class Main {
public static void main (String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" "); // 6 2
String[] input = br.readLine().split(" "); // 1 2 3 4 5 6
int n = Integer.parseInt(str[0]); // 6
int k = Integer.parseInt(str[1]); // 2
int [] arr = new int [n];
for(int i=0; i
Example 4: declare bufferedreader java
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Example 5: BufferredReader Class
package com.javatpoint;
import java.io.*;
public class BufferedReaderExample {
public static void main(String args[])throws Exception{
FileReader fr=new FileReader("D:\\testout.txt");
BufferedReader br=new BufferedReader(fr);
int i;
while((i=br.read())!=-1){
System.out.print((char)i);
}
br.close();
fr.close();
}
}
Example 6: 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();
}