buffered reader java 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(" ");
String[] input = br.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int k = Integer.parseInt(str[1]);
int [] arr = new int [n];
for(int i=0; i<n; i++)
{
arr[i] = Integer.parseInt(input[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: 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);
}
}