看一下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.这种情形说的很清楚
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.这种情形说的很清楚
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();"
测试通过