BufferedReader console=new BufferedReader(new InputStreamReader(System.in));//system.in shud be changed;

in this Line of code what ever is typed onto the keyboard gets into the console object,
I want the BufferedReader object to read from a variable

now my question is-what should be the parameter for BufferedReader Constructor??

8 Years
Discussion Span
Last Post by ~s.o.s~

If you search the internet (Yahoo) for:

java API BufferedReader

you will find the API of BufferedReader with all possible constructors.

Also what do you mean read from a variable. If you want a variable to be the input of the constructor, that variable will have to be one of types that the constructor accepts

InputStreamReader inputreader = ......

BufferedReader console=new BufferedReader(inputreader );

The constructor:

InputStreamReader(InputStream in)

Takes as argument an InputStream. Again if you check the API you will see that java.io.InputStream is an abstract class. So you might want to check the API for all know subclasses of that class.


> I want the BufferedReader object to read from a variable

If you are talking of having a Reader sort of wrapper for a target String, look into StringReader and Scanner.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.