IO-converted
IO-converted
Buffered Reader
Constructor Description
BufferedReader(Reader rd, int It is used to create a buffered character input stream that
size) uses the specified size for an input buffer.
Methods
Method Description
boolean ready() It is used to test whether the input stream is ready to be read.
Java-IO
Program1-file
import java.io.*;
public class BufferedReaderExample
{
public static void main(String args[])throws Exception
{
FileReader fr=new FileReader("D:\\ABC.txt");
BufferedReader br=new BufferedReader(fr);
int i;
while((i=br.read())!=-1){
System.out.print((char)i);
}
br.close();
fr.close();
}
}
import java.io.*;
public class BufferedReaderExample{
public static void main(String args[]) throws Exception{
Example Program1
import java.util.*;
class Scanner1{
public static void main(String args[])
{
Scanner1 sc = new Scanner1(System.in);
String name, age;
System.out.println("Enter Your Name :");
name=sc.nextLine();
System.out.println("Your Name is :"+name);
System.out.println("Enter Your age :");
age=sc.nextInt();
System.out.println("Your age is :"+ age);
}
}
Program2
import java.io.File;
import java.util.Scanner;
class Main
{
public static void main(String[] args) throws Exception
{
File file = new File("doc.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine())
{
System.out.println(sc.nextLine());
}
} }
Java-IO
Java Console
The Java Console class is be used to get input from console. It provides methods to read
texts and passwords. If you read password using Console class, it will not be displayed to
the user.
import java.io.Console;
class ReadStringTest{
Console c= System.console();
String n=c.readLine();
System.out.println("Welcome "+n);
Class BufferedWriter
Constructor
Methods
// Initialing BufferedWriter
BufferedWriter bw = new BufferedWriter(fr);
System.out.println("Buffered Writer start writing :)");
bw.write("hello"); //String
int i;
for(i=65;i<91;i++)
bw.write(i); //op-A-Z
}
}