import java.net.*;
import java.io.*;public class client
{
    static public PipedInputStream input = new PipedInputStream();
static public PipedOutputStream output = new PipedOutputStream(); static public byte[] buffer = new byte[10];
    public static void main(String[] args)
    {        try{
            input.connect(output );
        }catch (IOException ex) {
            System.out.println("connection"+ex);
        }
new Thread()
{
public void run()
{
buffer[0]='0';
buffer[1]='1';
buffer[2]='2'; while(true)
{
    try{
output.write(buffer,0,3);
}
catch(IOException e)
{
 System.out.println("------------------"+e); } }
}
}.start();
        new Thread()
        {
            public void run()
            {
                while( true ){
                    try{
                        
                        input.read( buffer, 0, 3);
                        System.out.println(new String(buffer));
                    }catch (IOException ex) {
                        System.out.println("------------------"+ex);
                    }
                }
            }
        }.start();
    }
}

解决方案 »

  1.   

    必须在一个CLASS里能访问吗?
      

  2.   

    package test;import java.net.*;
    import java.io.*;public class client
    {
        static public PipedInputStream input = new PipedInputStream();
        public static void main(String[] args)
        {
            try{
                input.connect( aa.output );
                new aa().start();/////////////////////////study_body添加
            }catch (IOException ex) {
                System.out.println("connection"+ex);
            }        new Thread()
            {
                public void run()
                {
                    while( true ){
                        try{
                            byte[] buffer = new byte[1];
                            input.read( buffer, 0, 1 );
                            System.out.println(new String(buffer));
                        }catch (IOException ex) {
                            System.out.println("------------------"+ex);
                        }
                    }
                }
            }.start();
        }
    }====================================================================
    package test;import java.net.*;
    import java.io.*;public class aa extends Thread
    {
        static public PipedOutputStream output = new PipedOutputStream();
        public void run()
        {
            while( true ){
                try{
                    output.write( new String("hello world").getBytes(), 0, new String("hello world").getBytes().length);
                    System.out.println("a");
                }catch (IOException ex) {
                    System.out.println(ex);
                }
            }
        }    public static void main(String[] args){
            try{
                output.connect( client.input );
            }catch (IOException ex) {
                System.out.println("connection"+ex);
            }        new aa().start();
        }
    }
    ================================================================
      

  3.   

    补充直接运行client就可以了。