+ 1
How do you print out something if user hasn't entered Any data in Scanner
2 Answers
+ 1
After reading line, you can check the value of the input variable with and if, so you print something if the value is null
0
boolean BufferedReader.ready() returns true if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
long waitTimeout = 30 * 1000; //30 Seconds
long startTime = System.currentTimeMillis();
InputStreamReader fileInputStream = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(fileInputStream);
while ((System.currentTimeMillis() < (startTime+timeout))) {
if (bufferedReader.ready()) {
System.out.println(bufferedReader.readLine());
}
}
System.out.println("Waited for input for "+timeout/1000.0+" seconds. \nRequest TImed Out");