Java IO Tutorial - Java Writer.write(String str, int off, int len)








Syntax

Writer.write(String str, int off, int len) has the following syntax.

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

Example

In the following code shows how to use Writer.write(String str, int off, int len) method.

//from www.j a  va2  s.  c o m
import java.io.*;

public class Main {

   public static void main(String[] args) {
      String str = "tutorial from java2s.com!";

      
      Writer writer = new PrintWriter(System.out);

      try {
         // write a string portion
         writer.write(str, 0, 5);

         // flush the writer
         writer.flush();

         // write another string portion
         writer.write(str, 5, 6);

         // flush the stream again
         writer.flush();

      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

The code above generates the following result.