Java IO Tutorial - Java PrintWriter.write(String s)








Syntax

PrintWriter.write(String s) has the following syntax.

public void write(String s)

Example

In the following code shows how to use PrintWriter.write(String s) method.

import java.io.*;
//from w w  w  . j  av a 2 s .  com
public class Main {

   public static void main(String[] args) {
      String s = "Hello";
      try {

         
         PrintWriter pw = new PrintWriter(System.out);

         // write strings
         pw.write(s);
         pw.write(" World");

         // flush the writer
         pw.flush();

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

The code above generates the following result.