Created
March 21, 2011 14:31
-
-
Save mneedham/879527 to your computer and use it in GitHub Desktop.
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
| 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