This discussion is archived
3 Replies Latest reply: Nov 11, 2012 2:01 PM by jschellSomeoneStoleMyAlias RSS

Writing to STDOUT, then reading from STDIN?

963096 Newbie
Currently Being Moderated
I have been researching this lately, as i've been programming 5 years and never had the opportunity to use it.

The documentation on the official Java tutorial is pretty scarce, but it SEEMS like i should be able to write to STDOUT, then have it wait for me until i read from STDIN.

I tried the following code:
PrintStream os = System.out;
System.setOut(os);
InputStream is = System.in;
System.setIn(is);
os.write("I HOPE THIS WORKS!!!!!!!!!".getBytes());
int available = is.available();
byte BYTE[] = new byte[6]; //just trying to read the first 6 bytes, for the heck of it!
is.read(BYTE);
However, when i run the os.write method, the String just prints to the console. i thought my code was sufficient to reassign it and prevent it from being output there. what am i missing here?

thanks!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points