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








Syntax

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

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

Example

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

/*from w w  w.  ja  va2  s. c  om*/
import java.io.*;

public class Main {

   public static void main(String[] args) {

      String s = "tutorial from java2s.com";

      
      StringWriter sw = new StringWriter();

      // write strings
      sw.write(s, 0, 4);
      sw.write(s, 5, 6);

      System.out.println(sw.toString());


   }
}

The code above generates the following result.