Reputation: 535
I am trying to pass a String to my BufferedReader
. How can I pass "test" as String
to the reader rather than the input from System.in
?
String test = "test";
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Upvotes: 36
Views: 44810
Reputation: 1776
You can modify your code as below
String test = "test";
Reader inputString = new StringReader(test);
BufferedReader reader = new BufferedReader(inputString);
Upvotes: 53
Reputation: 170713
No point in buffering a string. Just
String aString = ...;
Reader inFromUser = new StringReader(aString);
Upvotes: 11