sexroute(vivid) 
我试了,还是不对

解决方案 »

  1.   

    看一下JDK Doc:
    public int read()
             throws IOExceptionReads the next byte of data from this piped input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. If a thread was providing data bytes to the connected piped output stream, but the thread is no longer alive, then an IOException is thrown. Specified by:
    read in class InputStream
    Returns:
    the next byte of data, or -1 if the end of the stream is reached. 
    Throws: 
    IOException - if the pipe is broken.这种情形说的很清楚
      

  2.   

    public void run() {
    try {

    M.to_pipe.write(77);  // 语句2
    sleep(10*1000);
    System.out.println("tt finish");
    M.to_pipe.close();
    } catch( Exception e) { e.printStackTrace(); }
    }
    重写如上:加上"M.to_pipe.close();"
    测试通过
      

  3.   

    主要原因是从名称上看PipedOutputStream() PipedInPutStream();的内部输入输出方向同正常的输入输出方向是相反的,而输入流的read()方法又一直等待实际作为前端输入流的管道输出流关闭所以当手动关闭时就可以了。