In Java how to assign value to System.in?

java

Solution

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);

Problem

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.

Original source

Related problems