我正在尝试将字符串传递给我的BufferedReader
。如何将{test}作为String
传递给读者,而不是System.in
的输入?
String test = "test";
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
答案 0 :(得分:9)
您可以修改以下代码
String test = "test";
Reader inputString = new StringReader(test);
BufferedReader reader = new BufferedReader(inputString);
答案 1 :(得分:8)
缓冲字符串没有意义。只是
String aString = ...;
Reader inFromUser = new StringReader(aString);