目录

void write(int b)

描述 (Description)

java.io.PipedOutputStream.write(int b)方法将指定的字节写入管道输出流。 实现OutputStream的write方法。

声明 (Declaration)

以下是java.io.PipedOutputStream.write()方法的声明。

public void write(int b)

参数 (Parameters)

b - 要写入的字节。

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

IOException - 如果发生I/O错误。

例子 (Example)

以下示例显示了java.io.PipedOutputStream.write()方法的用法。

package com.iowiki;
import java.io.*;
public class PipedOutputStreamDemo extends PipedInputStream {
   public static void main(String[] args) {
      byte[] b = {'h', 'e', 'l', 'l', 'o'};
      // create a new Piped input and Output Stream
      PipedOutputStream out = new PipedOutputStream();
      PipedInputStreamDemo in = new PipedInputStreamDemo();
      try {
         // connect input and output
         out.connect(in);
         // write something 
         out.write(70);
         out.write(71);
         out.write(72);
         // flush the stream
         out.flush();
         // print what we wrote
         for (int i = 0; i < 3; i++) {
            System.out.print("" + (char) in.read());
         }
      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

FGH
↑回到顶部↑
WIKI教程 @2018