目录

void write(byte[] buf, int off, int len)

描述 (Description)

java.io.PrintStream.write()方法将从offset off开始的指定字节数组中的len个字节写入此流。 如果启用了自动刷新,则将调用flush方法。

请注意,字节将写为给定; 要编写将根据平台的默认字符编码进行翻译的字符,请使用print(char)或println(char)方法。

声明 (Declaration)

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

public void write(byte[] buf,int off,int len)

参数 (Parameters)

  • buf - 字节数组。

  • off - 从中开始取字节的偏移量。

  • len - 要写入的字节数。

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

NA

例子 (Example)

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

package com.iowiki;
import java.io.*;
public class PrintStreamDemo {
   public static void main(String[] args) {
      byte c[] = {70, 71, 72, 73, 74, 75, 76};
      // create printstream object
      PrintStream ps = new PrintStream(System.out);
      // write bytes 1-3
      ps.write(c, 1, 3);
      // flush the stream
      ps.flush();
   }
}

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

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