Possible Duplicate:
Writing data to System.in
We know that System.in
(Standard Input) is connected to console. So whenever we write in console it will flow to this stream. But is there any way to pass value to this Standard Input without entering from console, i.e. like System.in = "ABCD"
. I just want to imitate as the value is passing from console.
Yes, there is. Use System.setIn(InputStream in)
.
You can supply any subtype of InputStream
as well, so if you want to supply a specific value, you can use the StringBufferInputStream
, like so:
StringBufferInputStream s = new StringBufferInputStream("ABCD");
System.setIn(s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With