Lesson 12 | The flush() and close() methods of the Writer class |
Objective | Examine the methods of the Writer class used to flush and close files. |
flush( )
methodflush()
method.
public abstract void flush() throws IOExceptionIf necessary, this flushes the underlying stream as well.
close( )
methodclose()
method closes the writer and releases any resources associated with it.
public abstract void close() throws IOException
Class Writer java.lang.Object java.io.WriterAll Implemented Interfaces:
public abstract class Writer extends Object implements Appendable, Closeable, Flushable
Modifier and Type | Method and 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. |