目录

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

描述 (Description)

java.io.PrintWriter.write()方法写入一个字符数组的部分。

声明 (Declaration)

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

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

参数 (Parameters)

  • buf - 要写入的字符数组。

  • off - 从中开始写字符的偏移量。

  • len - 要写入的字符数。

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

NA

例子 (Example)

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

package com.iowiki;
import java.io.*;
public class PrintWriterDemo {
   public static void main(String[] args) {
      char[] c = {'a', 'b', 'c', 'd', 'e', 'f'};
      // create a new writer
      PrintWriter pw = new PrintWriter(System.out);
      // write char
      pw.write(c, 1, 3);
      pw.write(c, 3, 3);
      // flush the writer
      pw.flush();
   }
}

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

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