Created
March 16, 2022 10:28
-
-
Save quintesse/cac0f55e7f8e327779aa1e66a848f64e to your computer and use it in GitHub Desktop.
Input test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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