Java BufferedOutputStream write() Example
BufferedOutputStream class write() method example. This example shows you how to use write() method.
Syntax is : public void write(byte[] b, int off, int len) throws IOException
Method writes len bytes from the specified byte array starting at offset off to this buffered output stream.
Here is the code.
/**
* @(#) Write1BufferedOutputStream.java
* A class representing use of method write() of BufferedOutputStream
class in java.io Package.
* @Version 05-May-2008
* @author Rose India Team
*/
import java.io.*;
public class Write1BufferedOutputStream {
public static void main(String[] args) throws IOException{
String str = "MAHENDRA ";
byte[] byteArray = new byte[]{'S','I','N','G','H'};
// Create object of FileOutputStream class.
FileOutputStream objFileStream = new FileOutputStream("MAHENDRA");
// Create object of BufferedOutputStream class.
BufferedOutputStream obj = new BufferedOutputStream(objFileStream);
// write() method call.
obj.write(byteArray, 0, 5);
System.out.print("write method successfully written specified subarray.");
}
} |
Output of the program.
| write method successfully written specified subarray. |
|