Skip to content

Instantly share code, notes, and snippets.

@quintesse
Created March 16, 2022 10:28
Show Gist options
  • Save quintesse/cac0f55e7f8e327779aa1e66a848f64e to your computer and use it in GitHub Desktop.
Save quintesse/cac0f55e7f8e327779aa1e66a848f64e to your computer and use it in GitHub Desktop.
Input test
package dev.jbang.util;
import java.io.*;
public class input {
public static void main(String... args) throws IOException {
Reader r;
if (args.length == 0 || args[0].equals("-")) {
r = new InputStreamReader(System.in);
} else {
r = new FileReader(new File(args[0]));
}
BufferedReader br = new BufferedReader(r);
System.out.println("main() called.");
String input;
do {
System.out.println("Please type something: ");
try {
// wait until we have data to complete a readLine()
while (!br.ready()) {
Thread.sleep(200);
}
input = br.readLine();
} catch (InterruptedException e) {
System.out.println("main() cancelled");
return;
}
} while ("".equals(input));
System.out.println("Thank You for providing input: " + input);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment