void write(String str, int off, int len)


描述

所述java.io.FilterWriter.write(String str,int off,int len)方法写入一个字符串到过滤器写入器的一部分。

声明

以下是java.io.FilterWriter.write(String str,int off,int len)方法的声明

public void write(String str, int off, int len)

参数

  • str - 要写入Filter Writer的源字符串。

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

  • len - 要写入的字符数。

返回值

该方法不返回任何值。

异常

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

实例

以下示例显示了java.io.FilterWriter.write(String str,int off,int len)方法的用法。

package com.tutorialspoint;

import java.io.FilterWriter;
import java.io.StringWriter;
import java.io.Writer;

public class FilterWriterDemo {
   public static void main(String[] args) throws Exception {
      FilterWriter fw = null;
      Writer w = null;
      String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      String s = null;

      try {
         // create new reader
         w = new StringWriter(6);

         // filter writer
         fw = new FilterWriter(w) {
         };

         // write to filter writer
         fw.write(str, 5, 7);

         // get the string
         s = w.toString();

         // print
         System.out.print("String: "+s);

      } catch(Exception e) {
         // if any I/O error occurs
         e.printStackTrace();
      } finally {
         // releases system resources associated with this stream
         if(w!=null)
            w.close();
         if(fw!=null)
            fw.close();
      }
   }
}

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

String: FGHIJKL