Java.io.PrintStream.write() Method
Description
The java.io.PrintStream.write() method writes len bytes from the specified byte array starting at offset off to this stream. If automatic flushing is enabled then the flush method will be invoked. Note that the bytes will be written as given; to write characters that will be translated according to the platform's default character encoding, use the print(char) or println(char) methods.
Declaration
Following is the declaration for java.io.PrintStream.write() method
public void write(byte[] buf,int off,int len)
Parameters
buf -- A byte array
off -- Offset from which to start taking bytes
len -- Number of bytes to write
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, 71, 72, 73, 74, 75, 76};
// create printstream object
PrintStream ps = new PrintStream(System.out);
// write bytes 1-3
ps.write(c, 1, 3);
// flush the stream
ps.flush();
}
}
Let us compile and run the above program, this will produce the following result:
GHI