Java Writer.write(int c)

Syntax

Writer.write(int c) has the following syntax.

public void write(int c)  throws IOException

Example

In the following code shows how to use Writer.write(int c) method.


import java.io.*;
// w  ww. j  a v  a 2s  . c om
public class Main {

   public static void main(String[] args) {
      int c = 70;
      
      Writer writer = new PrintWriter(System.out);

      try {
         // write an int that will be printed as ASCII
         writer.write(c);

         // flush the writer
         writer.flush();

         // write another int that will be printed as ASCII
         writer.write(71);

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

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

The code above generates the following result.