zoukankan      html  css  js  c++  java
  • java 管道流

     1 package hjw;
    2 import java.io.IOException;
    3 import java.io.PipedInputStream;
    4 import java.io.PipedOutputStream;
    5 class Send implements Runnable{
    6 private PipedOutputStream pos=null;
    7 public Send(){
    8 this.pos=new PipedOutputStream();
    9 }
    10 public void run(){
    11 String str="Hello,World!";
    12 try{
    13 this.pos.write(str.getBytes());
    14 } catch (IOException e){
    15 e.printStackTrace();
    16 }
    17 try{
    18 this.pos.close();
    19 }catch (IOException r){
    20 r.printStackTrace();
    21 }
    22
    23 }
    24 public PipedOutputStream getPos(){
    25 return pos;
    26 }
    27 }
    28 class Receive implements Runnable{
    29 private PipedInputStream pis=null;
    30 public Receive(){
    31 this.pis=new PipedInputStream();
    32 }
    33 public void run(){
    34 byte b[]=new byte[1024];
    35 int len=0;
    36 try{
    37 len=this.pis.read(b);
    38 }catch (IOException e){
    39 e.printStackTrace();
    40 }
    41 try{
    42 this.pis.close();
    43 } catch (IOException e){
    44 e.printStackTrace();
    45 }
    46 System.out.println("接收的内容为:"+new String(b,0,len));
    47 }
    48 public PipedInputStream getPis(){
    49 return pis;
    50 }
    51 }
    52 public class PipedStreamDemo {
    53 public static void main(String[] args) {
    54 Send s=new Send();
    55 Receive r=new Receive();
    56 try{
    57 s.getPos().connect(r.getPis());
    58 }catch (IOException e){
    59 e.printStackTrace();
    60 }
    61 new Thread(s).start();
    62 new Thread(r).start();
    63 }
    64 }
  • 相关阅读:
    数据库连接
    TUniConnection连接
    在Bootstrap中得模态框(modal)中下拉不能显示得问题
    git ---匿名分支和checkout命令
    git ---合并和删除分支
    Git ---创建和切换分支
    git --删除文件、重命名
    git --版本对比
    git ---回到过去
    git ---查看工作状态和历史提交
  • 原文地址:https://www.cnblogs.com/dennisac/p/2410636.html
Copyright © 2011-2022 走看看