IO Management: BufferedReader Class

IO Management includes BufferedReader, InputStreamReader, FileInputStream, FileOutputStream, PrintWriter and many important classes.

In this blog, we will work on java.io package, BufferedReader, InputStreamReader classes and readLine() method.

IO Management Example

import java.io.*;

/*

                BufferedReader

                readLine() – method -> Return String value

*/

class io1

{

                public static void main(String args[]) throws IOException

                {

                                // Find the area of circle using readLine() method

                                double PI = 3.14;

                                int r;

 

                                double area;

 

                                InputStreamReader obj = new InputStreamReader(System.in);

                                BufferedReader br = new BufferedReader(obj);

                                //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

 

                                System.out.print(“Enter R : “);

                                r =  Integer.parseInt(br.readLine());

                                // r = int

                                // br.readLine() – wrapper class String

                                // String class to int data type

 

                                area = PI * r * r;

                                System.out.println(“Area of Circle = ” + area);   

                }

}

Output:

Enter R : 10

Area of Circle = 314.0

 

Video available on YouTube.

 


If you have any query on blog example, you can directly comment us or subscribe our website


[sbscrbr_form]

Earn Money Online

457total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.