In this tutorial, we will learn about Java FileOutputStream and its methods with the help of examples.
Java FileOutputStream is an output stream used for writing data to a file. If you have to write primitive values into a file, use FileOutputStream class. You can write byte-oriented as well as character-oriented data through FileOutputStream class. But, for character-oriented data, it is preferred to use FileWriter than FileOutputStream.
public class FileOutputStream extends OutputStream
Sr.No. | Method & Description |
---|---|
1 | void close()
This method closes this file output stream and releases any system resources associated with this stream. |
2 | protected void finalize()
This method cleans up the connection to the file, and ensures that the close method of this file output stream is called when there are no more references to this stream. |
3 | FileChannel getChannel()
This method returns the unique FileChannel object associated with this file output stream. |
4 | FileDescriptor getFD()
This method returns the file descriptor associated with this stream. |
5 | void write(byte[] b)
This method writes b.length bytes from the specified byte array to this file output stream. |
6 | void write(byte[] b, int off, int len)
This method writes len bytes from the specified byte array starting at offset off to this file output stream. |
7 | void write(int b)
This method writes the specified byte to this file output stream. |