一个发送类
import java.io.*;
public class Sender extends Thread{
private PipedOutputStream out = new PipedOutputStream();
public PipedOutputStream getPipedOutputStream()
{
return out;
}
public void run()
{
String s = new String("My name is Zhangzhibo");
try
{
out.write(s.getBytes());
}
    catch(Exception e)
    {
     e.printStackTrace();
    }
}
}
一个接收类
import  java.io.*;
public class Recer extends Thread {
private PipedInputStream in = new PipedInputStream();
public PipedInputStream getPipedInputStream()
{
return in;
}
public void run()
{
byte [] b = new byte[1024] ;
try
{
int len = in.read(b);
System.out.print(new String(b,0,len));
}
catch(Exception e)
{
e.printStackTrace();
}

}
}
一个启动类
import java.io.*;
public class Pipedtest { public static void main(String[] args) throws Exception {
// TODO: Add your code here
Sender s = new Sender();
Recer r = new Recer();
PipedOutputStream out = s.getPipedOutputStream();
PipedInputStream in = r.getPipedInputStream();
out.connect(in);
s.start();
r.start();
}
}