Skip to content

Most visited

Recently visited

navigation
Added in API level 1

OutputStream

public abstract class OutputStream
extends Object implements Closeable, Flushable

java.lang.Object
   ↳ java.io.OutputStream
Known Direct Subclasses
Known Indirect Subclasses


A writable sink for bytes.

Most clients will use output streams that write data to the file system (FileOutputStream), the network (getOutputStream()/getOutputStream()), or to an in-memory byte array (ByteArrayOutputStream).

Use OutputStreamWriter to adapt a byte stream like this one into a character stream.

Most clients should wrap their output stream with BufferedOutputStream. Callers that do only bulk writes may omit buffering.

Subclassing OutputStream

Subclasses that decorate another output stream should consider subclassing FilterOutputStream, which delegates all calls to the target output stream.

All output stream subclasses should override both write(int) and write(byte[],int,int). The three argument overload is necessary for bulk access to the data. This is much more efficient than byte-by-byte access.

See also:

Summary

Public constructors

OutputStream()

Default constructor.

Public methods

void close()

Closes this stream.

void flush()

Flushes this stream.

void write(byte[] buffer, int offset, int count)

Writes count bytes from the byte array buffer starting at position offset to this stream.

void write(byte[] buffer)

Equivalent to write(buffer, 0, buffer.length).

abstract void write(int oneByte)

Writes a single byte to this stream.

Inherited methods

From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Public constructors

OutputStream

Added in API level 1
OutputStream ()

Default constructor.

Public methods

close

Added in API level 1
void close ()

Closes this stream. Implementations of this method should free any resources used by the stream. This implementation does nothing.

Throws
IOException if an error occurs while closing this stream.

flush

Added in API level 1
void flush ()

Flushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does nothing.

Throws
IOException if an error occurs while flushing this stream.

write

Added in API level 1
void write (byte[] buffer, 
                int offset, 
                int count)

Writes count bytes from the byte array buffer starting at position offset to this stream.

Parameters
buffer byte: the buffer to be written.
offset int: the start position in buffer from where to get bytes.
count int: the number of bytes from buffer to write to this stream.
Throws
IOException if an error occurs while writing to this stream.
IndexOutOfBoundsException if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.

write

Added in API level 1
void write (byte[] buffer)

Equivalent to write(buffer, 0, buffer.length).

Parameters
buffer byte
Throws
IOException

write

Added in API level 1
void write (int oneByte)

Writes a single byte to this stream. Only the least significant byte of the integer oneByte is written to the stream.

Parameters
oneByte int: the byte to be written.
Throws
IOException if an error occurs while writing to this stream.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.