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??

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.