I am trying to read lines of text from the console. The number of rows is not known in advance. The BufferedReader.readLine () method reads a line, but after the last line expects input from the console. What needs to be done to avoid this?
The following is a snippet of code:
public static String[] getLinesFromConsole() {
String strLine = "";
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String line = "";
while ((line = br.readLine()) != null)
strLine += line + "~";
isr.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return strLine.split("~");
}
ambar source
share