Refer to the System.in class in Test , here is an example:
public class Test { public static void main(String[] args) { InputStream in = System.in; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int next = in.read(); while (next > -1) { bos.write(next); next = in.read(); } bos.flush(); byte[] bytes = bos.toByteArray(); System.out.println("output:" + new String(bytes)); } catch (IOException e) { e.printStackTrace(); } } }
source share