GeezerVison is showing docs.oracle.com — Writer (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.io
Class Writer
-
- All Implemented Interfaces:
- Closeable, Flushable, Appendable, AutoCloseable
- Direct Known Subclasses:
- BufferedWriter, CharArrayWriter, FilterWriter, OutputStreamWriter, PipedWriter, PrintWriter, StringWriter
public abstract class Writer
extends Object
implements Appendable, Closeable, Flushable
Abstract class for writing to character streams. The only methods that a
subclass must implement are write(char[], int, int), flush(), and close().
Most subclasses, however, will override some of the methods defined here in
order to provide higher efficiency, additional functionality, or both.
- Since:
- JDK1.1
- See Also:
Writer,
BufferedWriter,
CharArrayWriter,
FilterWriter,
OutputStreamWriter,
FileWriter,
PipedWriter,
PrintWriter,
StringWriter,
Reader
-
-
Field Summary
Fields
| Modifier and Type |
Field |
Description |
protected Object |
lock |
The object used to synchronize operations on this stream.
|
-
Constructor Summary
Constructors
| Modifier |
Constructor |
Description |
protected |
Writer() |
Creates a new character-stream writer whose critical sections will
synchronize on the writer itself.
|
protected |
Writer(Object lock) |
Creates a new character-stream writer whose critical sections will
synchronize on the given object.
|
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods
| Modifier and Type |
Method |
Description |
Writer |
append(char c) |
Appends the specified character to this writer.
|
Writer |
append(CharSequence csq) |
Appends the specified character sequence to this writer.
|
Writer |
append(CharSequence csq,
int start,
int end) |
Appends a subsequence of the specified character sequence to this writer.
|
abstract void |
close() |
Closes the stream, flushing it first.
|
abstract void |
flush() |
Flushes the stream.
|
void |
write(char[] cbuf) |
Writes an array of characters.
|
abstract void |
write(char[] cbuf,
int off,
int len) |
Writes a portion of an array of characters.
|
void |
write(int c) |
Writes a single character.
|
void |
write(String str) |
Writes a string.
|
void |
write(String str,
int off,
int len) |
Writes a portion of a string.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
write
public abstract void write(char[] cbuf,
int off,
int len)
throws IOException
Writes a portion of an array of characters.
- Parameters:
cbuf - Array of characters
off - Offset from which to start writing characters
len - Number of characters to write
- Throws:
IOException - If an I/O error occurs
-
write
public void write(String str,
int off,
int len)
throws IOException
Writes a portion of a string.
- Parameters:
str - A String
off - Offset from which to start writing characters
len - Number of characters to write
- Throws:
IndexOutOfBoundsException - If off is negative, or len is negative,
or off+len is negative or greater than the length
of the given string
IOException - If an I/O error occurs
-
close
public abstract void close()
throws IOException
Closes the stream, flushing it first. Once the stream has been closed,
further write() or flush() invocations will cause an IOException to be
thrown. Closing a previously closed stream has no effect.
- Specified by:
close in interface Closeable
- Specified by:
close in interface AutoCloseable
- Throws:
IOException - If an I/O error occurs
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|