本文共 2401 字,大约阅读时间需要 8 分钟。
receive() method is available in java.io package.
receive()方法在java.io包中可用。
receive() method is used to receive a byte of content and it will block when no more input remains.
receive()方法用于接收内容的一个字节,当不再有剩余输入时它将阻塞。
receive() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
receive()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
receive() method may throw an exception at the time of receiving a byte of data.
receive()方法在接收到一个字节数据时可能会引发异常。
IOException: This exception may throw when getting any input/output error or pipe not connected properly, or stream closed.
IOException :当出现任何输入/输出错误或管道未正确连接或流关闭时,可能引发此异常。
Syntax:
句法:
protected void receive(int byt);
Parameter(s):
参数:
int byt – represents the byte getting received.
int byt –表示要接收的字节。
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example // of receive(int byt) method of PipedInputStreamimport java.io.*;public class ReceiveOfPIS extends PipedInputStream { public static void main(String[] args) throws Exception { int val = 65; try { // Instantiates ReceiveOfPIS and // PipedOutputStream ReceiveOfPIS pipe_in = new ReceiveOfPIS(); PipedOutputStream pipe_out = new PipedOutputStream(); // By using connect() method is to // connect this pipe_in to the given pipe_out pipe_in.connect(pipe_out); for (int i = 0; i < 3; ++i) { // By using write() method is to // write the val to the stream pipe_out pipe_out.write(val); val++; } for (int i = 1; i < 4; ++i) { // By using receive() method is to // receive a byte pipe_in.receive(val); System.out.println(i + " " + "Byte Received "); } // By using close() method is to close // the stream pipe_in.close(); pipe_out.close(); } catch (Exception ex) { System.out.println(ex.toString()); } }}
Output
输出量
1 Byte Received 2 Byte Received 3 Byte Received
翻译自:
转载地址:http://eftzd.baihongyu.com/