Import Java.io.bufferedinputstream;import Java.io.bytearrayinputstream;import Java.io.ByteArrayOutputStream; Import Java.io.ioexception;import Java.io.inputstream;import Org.junit.test;public class Testio { Bytearrayoutputstream BAOs = new Bytearrayoutputstream (), @Testpublic void Test1 () throws Exception {Process exec = Runtime . GetRuntime (). EXEC ("ipconfig"); InputStream InputStream = Exec.getinputstream (); byte[] bytes = new Byte[1024];int len = 0 ;//bytearrayinputstream Bais = new while ((Len=inputstream.read (bytes))!=-1) {//inputstream.read (bytes); Baos.write ( Bytes,0,len);} Baos.flush (); thread T1 = new Thread (new Runnable () {byte[] temp = new byte[1024];byte[] ByteArray = Baos.tobytearray (); Bytearrayinputstream Bais = new Bytearrayinputstream (ByteArray); Bufferedinputstream bis = new Bufferedinputstream (bais); int len=0; StringBuilder sb = new StringBuilder ();p ublic void Run () {//TODO auto-generated method Stubtry {while ((Len=bis.read (temp) ) {!=-1) {sb.append (new String (Temp,0,len));} System.out.println (Sb.tostring ());} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}); Thread t2 = new Thread (new Runnable () {byte[] temp = new byte[1024];byte[] ByteArray = Baos.tobytearray (); Bytearrayinputstream Bais = new Bytearrayinputstream (ByteArray); Bufferedinputstream bis = new Bufferedinputstream (bais); int len=0; StringBuilder sb = new StringBuilder ();p ublic void Run () {//TODO auto-generated method Stubtry {while ((Len=bis.read (temp) ) {!=-1) {sb.append (new String (Temp,0,len));} System.out.println (Sb.tostring ());} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}); T1.start (); T2.start ();}}
BAOs Bais Significance