Java IO Tutorial - 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.*;
/*from  w  w  w.j av  a 2  s.  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.