以下程序中的 while 循环不会终止,因此我无法在尝试将变量段落打印到控制台的最后一行中获得输出。有类似的问题,但解决方案不切实际,我无法做到。请提出解决方案。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws IOException {
String line = "";
String paragraph = "";
System.out.println("Enter the text: ");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(isr);
while ((line = bufferedReader.readLine()) != null)
{
paragraph = paragraph + line + " ";
}
isr.close();
bufferedReader.close();
System.out.println(paragraph);
}//method main ends here
}