Skip to content

Instantly share code, notes, and snippets.

@mneedham
Created March 21, 2011 14:31
Show Gist options
  • Select an option

  • Save mneedham/879527 to your computer and use it in GitHub Desktop.

Select an option

Save mneedham/879527 to your computer and use it in GitHub Desktop.
PipedOutputStream poStream = new PipedOutputStream();
PipedInputStream piStream = new PipedInputStream();
System.setIn(piStream);
poStream.connect(piStream);
poStream.write("19".getBytes(), 0, 1);
Program.main();
Program
public class Program {
public static void main(String... args) {
while(true) {
InputStreamReader inputStream = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(inputStream);
int i1 = 0;
try {
i1 = Integer.parseInt(reader.readLine());
} catch (Exception e) {
// Do you know what numbers are!!!
System.out.println("Enter a valid integer!!");
}
// code further down does stuff with i1
}
}
}
I want to get 2 different values when reader.readLine() gets called.
The first time the value it reads would be "1" and the second time it should be "9"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment