Java IO Tutorial - Java PrintWriter.print(boolean b)








Syntax

PrintWriter.print(boolean b) has the following syntax.

public void print(boolean b)

Example

In the following code shows how to use PrintWriter.print(boolean b) method.

/*  w ww  . j a v a 2  s  . c o  m*/
import java.io.*;

public class Main {

   public static void main(String[] args) {
      boolean bool = false;
      try {

         
         PrintWriter pw = new PrintWriter(System.out);

         // print a boolean
         pw.print(true);

         // change the line
         pw.println();

         // print another boolean
         pw.print(bool);

         // flush the writer
         pw.flush();

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

The code above generates the following result.