wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Can same BufferedReader take multiple inputs? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can same BufferedReader take multiple inputs?" Watch "Can same BufferedReader take multiple inputs?" New topic
Author

Can same BufferedReader take multiple inputs?

Yudi Strange
Greenhorn

Joined: Jun 04, 2009
Posts: 7
I tried using the same buffer reader for taking different inputs. But it's not working properly. Please explain why?


anandhi mohan
Greenhorn

Joined: Mar 24, 2009
Posts: 9
you can use same buffer reader to get different input.
In your code, you are closing the bufferreader before it reads the input thats why it throws some exceptions.

try this:

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
String a;
System.out.println("Enter Name");
a=br.readLine();
nme=a;
System.out.println("Enter Amount");
a=br.readLine();
bn=Double.parseDouble(a);
System.out.println("Enter rollno.");
a=br.readLine();
double x=Double.parseDouble(a);
Long ac_no=(long)x;
br.close();
}
catch(Exception e)
{

System.out.println("Exception encountered");
}
Lei Guoguo
Greenhorn

Joined: Mar 31, 2009
Posts: 26

uper code is java source in java.io.BufferedReader, you know , in this method, in = null;

see under code

key code is super(in);
now , we can see the super class java.io.Reader


i think, you are understood, the inputstream in bufferedreader is null when we close the invoke java.io.BufferedReader.close()


I'm a chinese, my english is so bad, I need help. If you want to help me, you can send your question to my e-mail: lgg860911@yahoo.com.cn, I will help you, and improve my english. Thanks everyone.
Yudi Strange
Greenhorn

Joined: Jun 04, 2009
Posts: 7
Thanks
 
 
subject: Can same BufferedReader take multiple inputs?