Java.io.PrintWriter.write() Method

Advertisements


Description

The java.io.PrintWriter.write() method writes an array of characters.

Declaration

Following is the declaration for java.io.PrintWriter.write() method

public void write(char[] buf)

Parameters

  • buf -- Array of characters to be written

Return Value

This method does not return a value.

Exception

  • NA

Example

The following example shows the usage of java.io.PrintWriter.write() method.

package com.tutorialspoint;

import java.io.*;

public class PrintWriterDemo {

   public static void main(String[] args) {
      char c = 'a';

      // create a new writer
      PrintWriter pw = new PrintWriter(System.out);

      // write char
      pw.write(c);
      pw.write('b');

      // flush the writer
      pw.flush();

   }
}

Let us compile and run the above program, this will produce the following result:

ab



Advertisements
Advertisements