Java.io.PrintStream.write() Method



Description

The java.io.PrintStream.write() method Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the flush method will be invoked.

Declaration

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

public void write(int b)

Parameters

b − The byte to be written.

Return Value

This method does not return a value.

Exception

NA

Example

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

package com.tutorialspoint;

import java.io.*;

public class PrintStreamDemo {
   public static void main(String[] args) {
      byte c = 70;

      // create printstream object
      PrintStream ps = new PrintStream(System.out);

      // write byte c which is character F in ASCII
      ps.write(c);

      // flush the stream
      ps.flush();
   }
}

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

F
java_io_printstream.htm
Advertisements