baos bais 意义
2015-11-20 17:23
441 查看
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(); @Test public 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(); public void run() { // TODO Auto-generated method stub try { 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 block e.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(); public void run() { // TODO Auto-generated method stub try { 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 block e.printStackTrace(); } } }); t1.start(); t2.start(); } }
相关文章推荐
- [AlwaysOn Availability Groups]排查:AG超过RPO
- pthread_cond_wait() 前使用 while 讲解
- AEAI DP按钮权限配置说明
- AEAI DP按钮权限配置说明
- Wait函数和waitpid函数详解----很好
- [AlwaysOn Availability Groups]排查:AG超过RTO
- hdu 1151 Air Raid 匹配
- Daily Scrum - 11/20
- Factorial Trailing Zeroes
- 解决启动报错:Failed to destroy end point associated with ProtocolHandler["ajp-nio-8009"]
- Robotium 运行时Installation error INSTALL_FAILED_VERSION_DOWNGRADE错误
- UVa 442 ------ Matrix Chain Multiplication
- C语言问题 赋值表达式返回值是什么 http://zhidao.baidu.com/link?url=FrmzIbFTHGAGizJ4aBU7r93lWwOTOuVh4WLMAJ3DA0wRRnqS
- 类1调用类2的子方法不会触发类2的main方法
- Maven编译错误:Could not generate DH keypair: Prime size must be multiple of 64...
- 【HDU5411 2015 Multi-University Training Contest 10F】【矩阵快速幂 加一行构造法】CRB and Puzzle 矩阵的1次方到n次方的数值和
- 单击Main.StoryBoard文件,XCODE自动关闭
- [BetterExplained]如何有效地记忆与学习
- retain、strong、weak、assign区别
- 【HDOJ】5046 Airport