標籤:catch byte sharp arp 產生 ble read hello err
class Send implements Runnable{PipedOutputStream pos = null;public Send(){this.pos = new PipedOutputStream();}public PipedOutputStream getPipedOutputStream(){return this.pos;}@Overridepublic void run() {// TODO 自動產生的方法存根String str = "hello world!!!";try {this.pos.write(str.getBytes());} catch (IOException e) {// TODO 自動產生的 catch 塊e.printStackTrace();}try {this.pos.close();} catch (IOException e) {// TODO 自動產生的 catch 塊e.printStackTrace();}}}class Receive implements Runnable{PipedInputStream pis = null;public Receive(){this.pis = new PipedInputStream();}public PipedInputStream getPipedInputStream(){return this.pis;}@Overridepublic void run() {// TODO 自動產生的方法存根byte b[] = new byte[1024];int len = 0;try {len = this.pis.read(b);} catch (IOException e) {// TODO 自動產生的 catch 塊e.printStackTrace();}try {this.pis.close();} catch (IOException e) {// TODO 自動產生的 catch 塊e.printStackTrace();}System.out.println(new String(b,0,len) );}}public class PipedOutputStreamDemo {public static void main(String[] args) throws Exception {// TODO 自動產生的方法存根Send send = new Send();Receive rec = new Receive();send.getPipedOutputStream().connect(rec.getPipedInputStream());new Thread(send).start();new Thread(rec).start();}}
java:管道流(線程間管道流)