Java FileOutputStream write() Example
FileOutputStream 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 file output stream.
Here is the code.
/**
* @(#) Write1FileOutputStream.java
* A class representing use of method write() of FileOutputStream
class in java.io Package.
* @Version 05-June-2008
* @author Rose India Team
*/
import java.io.*;
public class Write1FileOutputStream {
public static void main(String[] args) throws IOException {
byte[] byteArray = new byte[]{'S','I','N','G','H','G','Q'};
// Create object of FileOutputStream class
FileOutputStream objFileStream = new FileOutputStream("MAHENDRA");
// write() method call.
objFileStream.write(byteArray, 0, 5);
System.out.print("Specified byte subarray has written successfully to "
+ "file output stream.");
}
} |
output of the program.
| Specified byte subarray has written successfully to file output stream. |
|