Java.io.FilterWriter.write string() 方法


Java.io.FilterWriter.write string() 方法

package com.codingdict;



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();

      }

   }

}