java.lang.Object | ||
↳ | java.io.Writer | |
↳ | java.io.BufferedWriter |
Wraps an existing Writer
and buffers the output. Expensive
interaction with the underlying reader is minimized, since most (smaller)
requests can be satisfied by accessing the buffer alone. The drawback is that
some extra space is required to hold the buffer and that copying takes place
when filling that buffer, but this is usually outweighed by the performance
benefits.
BufferedWriter buf = new BufferedWriter(new FileWriter("file.java"));
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
BufferedWriter , providing out with a buffer
of 8192 bytes. | |||||||||||
Constructs a new
BufferedWriter , providing out with size bytes
of buffer. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes this writer.
| |||||||||||
Flushes this writer.
| |||||||||||
Writes a newline to this writer.
| |||||||||||
Writes
count characters starting at offset in
cbuf to this writer. | |||||||||||
Writes
count characters starting at offset in str
to this writer. | |||||||||||
Writes the character
oneChar to this writer. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Constructs a new BufferedWriter
, providing out
with a buffer
of 8192 bytes.
out | the Writer the buffer writes to.
|
---|
Constructs a new BufferedWriter
, providing out
with size
bytes
of buffer.
out | the OutputStream the buffer writes to. |
---|---|
size | the size of buffer in bytes. |
Public Methods
public
void
close
()
Since: API Level 1
Closes this writer. The contents of the buffer are flushed, the target
writer is closed, and the buffer is released. Only the first invocation
of close has any effect.
public
void
flush
()
Since: API Level 1
Flushes this writer. The contents of the buffer are committed to the
target writer and it is then flushed.
public
void
newLine
()
Since: API Level 1
Writes a newline to this writer. A newline is determined by the System
property "line.separator". The target writer may or may not be flushed
when a newline is written.
public
void
write
(char[] cbuf, int offset, int count)
Since: API Level 1
Writes
count
characters starting at offset
in
cbuf
to this writer. If count
is greater than this
writer's buffer, then the buffer is flushed and the characters are
written directly to the target writer.
Parameters
cbuf
| the array containing characters to write. |
---|---|
offset
| the start position in |
count
| the maximum number of characters to write. |
Throws
IndexOutOfBoundsException
| if |
---|---|
IOException
| if this writer is closed or another I/O error occurs.
|
public
void
write
(String str, int offset, int count)
Since: API Level 1
Writes
count
characters starting at offset
in str
to this writer. If count
is greater than this writer's buffer,
then this writer is flushed and the remaining characters are written
directly to the target writer. If count is negative no characters are
written to the buffer. This differs from the behavior of the superclass.
Parameters
str
| the non-null String containing characters to write. |
---|---|
offset
| the start position in |
count
| maximum number of characters to write. |
Throws
IOException
| if this writer has already been closed or another I/O error
occurs. |
---|---|
IndexOutOfBoundsException
| if |
public
void
write
(int oneChar)
Since: API Level 1
Writes the character
oneChar
to this writer. If the buffer
gets full by writing this character, this writer is flushed. Only the
lower two bytes of the integer oneChar
are written.
Parameters
oneChar
| the character to write. |
---|